From: Radek Czajka Date: Tue, 7 Sep 2010 12:21:12 +0000 (+0200) Subject: autotagging X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/483b49a917211353f1707012c77531cc0d06d99f autotagging --- diff --git a/apps/toolbar/fixtures/initial_data.yaml b/apps/toolbar/fixtures/initial_data.yaml index 1702c014..e158c080 100644 --- a/apps/toolbar/fixtures/initial_data.yaml +++ b/apps/toolbar/fixtures/initial_data.yaml @@ -4,6 +4,9 @@ - fields: {name: Autokorekta, position: 0, slug: autokorekta} model: toolbar.buttongroup pk: 2 +- fields: {name: Autotagowanie, position: 0, slug: autotagowanie} + model: toolbar.buttongroup + pk: 28 - fields: {name: Bloki, position: 0, slug: bloki} model: toolbar.buttongroup pk: 21 @@ -70,6 +73,17 @@ tooltip: wstawia akapit dialogowy model: toolbar.button pk: 41 +- fields: + accesskey: '' + group: [28] + label: akapity + link: '' + params: '{"tag": "akap"}' + scriptlet: autotag + slug: akapity + tooltip: "autotagowanie akapit\xF3w" + model: toolbar.button + pk: 97 - fields: accesskey: '' group: [1] @@ -643,6 +657,17 @@ tooltip: "wstawia strof\u0119" model: toolbar.button pk: 81 +- fields: + accesskey: '' + group: [28] + label: strofy + link: '' + params: '{"tag": "strofa"}' + scriptlet: autotag + slug: strofy + tooltip: autotagowanie strof + model: toolbar.button + pk: 99 - fields: accesskey: '' group: [11] @@ -742,6 +767,17 @@ tooltip: "wstawia wers wci\u0119ty" model: toolbar.button pk: 91 +- fields: + accesskey: '' + group: [28] + label: "wersy wci\u0119te" + link: '' + params: '{"padding": 1, "tag": "wers_wciety", "split": 1}' + scriptlet: autotag + slug: wersy-wciete + tooltip: "autotagowanie wers\xF3w wci\u0119tych" + model: toolbar.button + pk: 100 - fields: accesskey: '' group: [15] @@ -892,4 +928,7 @@ \r\n\r\n\r\n\r\n\r\n\r\n\r\npanel.fireEvent('contentChanged');"} model: toolbar.scriptlet pk: insert_stanza +- fields: {code: '-'} + model: toolbar.scriptlet + pk: autotag diff --git a/redakcja/static/js/button_scripts.js b/redakcja/static/js/button_scripts.js index de3b5ee9..c3275938 100644 --- a/redakcja/static/js/button_scripts.js +++ b/redakcja/static/js/button_scripts.js @@ -114,7 +114,6 @@ function ScriptletCenter() }; }); - var partial = true; if(!text) done(text, move_forward); var changed = 0; @@ -155,7 +154,6 @@ function ScriptletCenter() }); if(!text) done(text, move_forward); - var original = text;$ nblck_each(exprs, function(expr, index) { $progress.html(600 + index); @@ -217,6 +215,45 @@ function ScriptletCenter() done(text, move_forward); }.bind(this); + + this.scriptlets['autotag'] = function(context, params, text, move_forward, done) + { + if(!text.match(/^\n+$/)) done(text, move_forward); + + function insert_done(output, mf) { + text += output; + } + + if (!params.split) params.split = 2; + if (!params.padding) params.padding = 3; + + chunks = text.replace(/^\n+|\n+$/, '').split(new RegExp("\\n{"+params.split+",}")); + text = text.match(/^\n+/); + if (!text) + text = ''; + padding = ''; + for(; params.padding; params.padding--) { + padding += "\n"; + } + + if (params.tag == 'strofa') + tagger = this.scriptlets['insert_stanza']; + else + tagger = this.scriptlets['insert_tag']; + + for (i in chunks) { + if (chunks[i]) { + if (params.tag == 'akap' && chunks[i].match(/^---/)) + tag = 'akap_dialog'; + else tag = params.tag; + tagger(context, {tag: tag}, chunks[i], 0, insert_done); + text += padding; + } + } + + done(text, move_forward); + }.bind(this); + } ScriptletCenter.prototype.callInteractive = function(opts) {