-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
2,667 additions
and
148,782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class EditorButton < ApplicationRecord | ||
belongs_to :collection | ||
|
||
module Keys | ||
ABBR = 'abbr' | ||
ADD = 'add' | ||
DATE = 'date' | ||
DEL = 'del' | ||
EXPAN = 'expan' | ||
FIG = 'fig' | ||
GAP = 'gap' | ||
REG = 'reg' | ||
STRIKE = 's' | ||
SUB = 'sub' | ||
SUP = 'sup' | ||
UNCLEAR = 'unclear' | ||
UNDERLINE = 'u' | ||
end | ||
|
||
BUTTON_MAP = { | ||
Keys::ABBR => ['<abbr expan="">'], | ||
Keys::ADD => ['<add>'], | ||
Keys::DATE => ['<date when="">'], | ||
Keys::DEL => ['<del>'], | ||
Keys::EXPAN => ['<expan abbr="">'], | ||
Keys::FIG => ['<fig rend="hr">'], | ||
Keys::GAP => ['<gap>'], | ||
Keys::REG => ['<reg orig="">'], | ||
Keys::STRIKE => ['<hi rend="str">', '<s>'], | ||
Keys::SUB => ['<hi rend="sub">', '<sub>'], | ||
Keys::SUP => ['<hi rend="sup">', '<sup>'], | ||
Keys::UNCLEAR => ['<unclear>'], | ||
Keys::UNDERLINE => ['<hi rend="underline">', '<u>'] | ||
} | ||
|
||
|
||
def open_tag | ||
tags = BUTTON_MAP[self.key] | ||
if self.prefer_html && tags.size > 1 | ||
tags[1].html_safe | ||
else | ||
tags[0].html_safe | ||
end | ||
end | ||
|
||
|
||
def close_tag | ||
('</' + open_tag.sub('<', '').sub(/\s.*/, '').sub('>','') + '>').html_safe | ||
end | ||
|
||
def cursor_offset | ||
self.close_tag.length | ||
end | ||
|
||
def has_attribute | ||
open_tag.match /\s/ | ||
end | ||
|
||
def hotkey | ||
"Ctrl-E" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
h2.nomargin =t('.heading') | ||
p =t('.description') | ||
=form_with(url: collection_editor_button_update_path, local: true) do |f| | ||
=hidden_field_tag :collection_id, @collection.slug | ||
-buttons = @collection.editor_buttons.to_a.map { |b| b.key} | ||
ul.edit-buttons | ||
-EditorButton::BUTTON_MAP.keys.each do |key| | ||
li | ||
.edit-buttons_format | ||
h5 | ||
=t(".#{key}_label") | ||
p.nomargin =t(".#{key}_description") | ||
.edit-buttons_options | ||
=f.label key | ||
=check_box_tag key, '1', buttons.include?(key) | ||
span | ||
-if EditorButton::BUTTON_MAP[key].size > 1 | ||
code | ||
=EditorButton::BUTTON_MAP[key][0] | ||
=t('.tei') | ||
br | ||
code | ||
=EditorButton::BUTTON_MAP[key][1] | ||
=t('.html') | ||
-else | ||
code | ||
=EditorButton::BUTTON_MAP[key][0] | ||
li | ||
.edit-buttons_format | ||
h5 =t('.markup_preference_label') | ||
p.nomargin =t('.markup_preference_description') | ||
.edit-buttons_options | ||
=f.label :prefer_html_true | ||
=radio_button_tag :prefer_html, :true, @prefer_html | ||
span =t('.prefer_html') | ||
=f.label :prefer_html_false | ||
=radio_button_tag :prefer_html, :false, !@prefer_html | ||
span =t('.prefer_tei') | ||
|
||
|
||
.toolbar | ||
.toolbar_group.aright =f.button 'Save', class: 'big', 'data-start-export': '' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<%=stylesheet_link_tag "codemirror/lib/codemirror"%> | ||
<%=stylesheet_link_tag "codemirror-buttons/buttons"%> | ||
<%=javascript_include_tag "codemirror/lib/codemirror"%> | ||
<%=javascript_include_tag "codemirror/mode/xml/xml"%> | ||
<%=javascript_include_tag "codemirror/addon/display/display/panel"%> | ||
<%=javascript_include_tag "codemirror/addon/hint/show-hint"%> | ||
<%=javascript_include_tag "codemirror/addon/hint/xml-hint"%> | ||
<%=javascript_include_tag "codemirror-buttons/buttons"%> | ||
|
||
<script> | ||
var button_config = [ | ||
<% @collection.editor_buttons.each do |button| %> | ||
{ | ||
hotkey: '<%= button.hotkey %>', | ||
class: '<%= "editor-buttons-#{button.key}" %>', | ||
label: '<%= "#{button.key}" %>', | ||
callback: function (cm) { | ||
var selection = cm.getSelection(); | ||
cm.replaceSelection('<%= button.open_tag %>' + selection + '<%= button.close_tag %>'); | ||
if (!selection) { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - <%= button.cursor_offset %>); | ||
} | ||
<% if button.has_attribute %> | ||
else { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - <%= button.cursor_offset %> - selection.length - 2); | ||
} | ||
<% end %> | ||
} | ||
}, | ||
<% end %> | ||
]; | ||
|
||
var fromthepage_tags = { | ||
"!top": ["abbr", "add", "cb", "date", "del", "expan", "figure", "gap", "hi", "ins", "milestone", "reg", "stamp", "sub", "sup", "table", "unclear", "u", "strike", "s", "span", "a"], | ||
abbr: { attrs: { expan: null}}, | ||
add: { children: ["u", "s", "hi"] }, | ||
cb: { attrs: { "n": null } }, | ||
date: {attrs: { when: "YYYY-MM-DD" }, children: ["hi", "unclear", "gap"] }, | ||
expan: {attrs: { abbr: null }}, | ||
figure: { attrs: { "type": ["hr", "postmark", "seal"] }}, | ||
hi: { attrs: { "rend": ["bold", "italic", "str", "sub", "sup", "underline"]}}, | ||
ins: { children: ["u", "s", "hi"]}, | ||
milestone: { attrs: { "unit": ["column"], "n": null}}, | ||
reg: {attrs: { orig: null }}, | ||
row: { children: ["cell"] }, | ||
stamp: { attrs: {"type": ["clerical", "postage", "revenue"]}}, | ||
sup: { children: ["u", "s"] }, | ||
table: { attrs: {"rend": ["rules"]}, children: ["row"] } | ||
} | ||
|
||
|
||
function completeAfter(cm, pred) { | ||
var cur = cm.getCursor(); | ||
if (!pred || pred()) setTimeout(function() { | ||
if (!cm.state.completionActive) | ||
cm.showHint({completeSingle: false}); | ||
}, 100); | ||
return CodeMirror.Pass; | ||
} | ||
|
||
function completeIfAfterLt(cm) { | ||
return completeAfter(cm, function() { | ||
var cur = cm.getCursor(); | ||
return cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur) == "<"; | ||
}); | ||
} | ||
|
||
function completeIfInTag(cm) { | ||
return completeAfter(cm, function() { | ||
var tok = cm.getTokenAt(cm.getCursor()); | ||
if (tok.type == "string" && (!/['"]/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1)) return false; | ||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state).state; | ||
return inner.tagName; | ||
}); | ||
} | ||
|
||
var myCodeMirror = CodeMirror.fromTextArea( | ||
document.getElementById("<%= textarea %>"), | ||
{ | ||
lineNumbers: true, | ||
mode: "xml", | ||
extraKeys: { | ||
"'<'": completeAfter, | ||
"'/'": completeIfAfterLt, | ||
"' '": completeIfInTag, | ||
"'='": completeIfInTag, | ||
"Ctrl-Space": "autocomplete", | ||
"Tab": "autocomplete" | ||
}, | ||
lineWrapping: true, | ||
hintOptions: {schemaInfo: fromthepage_tags}, | ||
buttons: button_config | ||
}); | ||
|
||
<% if has_title %> | ||
myCodeMirror.setSize("100%", "91.5%"); | ||
<% else %> | ||
myCodeMirror.setSize("100%", "100%"); | ||
<% end %> | ||
</script> |
Oops, something went wrong.