simple_form_markdown_editor 0.0.10 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +70 -58
  4. data/app/controllers/simple_form_markdown_editor/previews_controller.rb +19 -7
  5. data/lib/assets/javascripts/simple_form_markdown_editor.js +1 -3
  6. data/lib/assets/javascripts/simple_form_markdown_editor/__buttons.coffee.erb +48 -0
  7. data/lib/assets/javascripts/simple_form_markdown_editor/__editor.coffee.erb +81 -0
  8. data/lib/assets/javascripts/simple_form_markdown_editor/__help.coffee.erb +86 -0
  9. data/lib/assets/javascripts/simple_form_markdown_editor/__preview.coffee.erb +42 -0
  10. data/lib/assets/javascripts/simple_form_markdown_editor/__tabs.coffee.erb +59 -0
  11. data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor.coffee.erb +98 -0
  12. data/lib/assets/stylesheets/simple_form_markdown_editor.css +2 -2
  13. data/lib/assets/stylesheets/simple_form_markdown_editor/_partials.scss +5 -0
  14. data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button.scss.erb +4 -0
  15. data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_group.scss.erb +5 -0
  16. data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_wrapper.scss.erb +5 -0
  17. data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__buttons.scss.erb +9 -0
  18. data/lib/assets/stylesheets/simple_form_markdown_editor/editor/__editor.scss.erb +4 -0
  19. data/lib/assets/stylesheets/simple_form_markdown_editor/header/__header.scss.erb +4 -0
  20. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help.scss.erb +12 -0
  21. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__section.scss.erb +3 -0
  22. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sections.scss.erb +5 -0
  23. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section.scss.erb +9 -0
  24. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__item.scss.erb +7 -0
  25. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__items.scss.erb +5 -0
  26. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_sections.scss.erb +5 -0
  27. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__text.scss.erb +9 -0
  28. data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__texts.scss.erb +5 -0
  29. data/lib/assets/stylesheets/simple_form_markdown_editor/preview/__preview.scss.erb +4 -0
  30. data/lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.scss.erb +23 -0
  31. data/lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tab.scss.erb +8 -0
  32. data/lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tabs.scss.erb +9 -0
  33. data/lib/simple_form_markdown_editor.rb +11 -3
  34. data/lib/simple_form_markdown_editor/markdown_editor_input.rb +41 -53
  35. data/lib/simple_form_markdown_editor/version.rb +1 -1
  36. data/simple_form_markdown_editor.gemspec +4 -1
  37. metadata +72 -7
  38. data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_buttons.coffee.erb +0 -114
  39. data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_help.coffee +0 -92
  40. data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_tabs.coffee +0 -82
  41. data/lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.css.scss +0 -274
@@ -0,0 +1,42 @@
1
+ # https://github.com/jquery-boilerplate/jquery-boilerplate/
2
+ do ($ = jQuery, window, document) ->
3
+ pluginName = 'simple_form_markdown_editor__preview'
4
+ defaults =
5
+ debug: false
6
+
7
+ class Plugin
8
+ constructor: (@element, options) ->
9
+ @settings = $.extend {}, defaults, options
10
+
11
+ @$element = $(@element)
12
+
13
+ @_defaults = defaults
14
+ @_name = pluginName
15
+
16
+ @init()
17
+
18
+ init: ->
19
+ @$element.on 'show_preview', (e) =>
20
+ e.stopPropagation()
21
+ content = e.html or "<p>" + @get_nothing_to_preview_text() + "</p>"
22
+ @$element.html(content)
23
+
24
+ get_nothing_to_preview_text: ->
25
+ @$element.data('nothing-to-preview-text') or 'Nothing to preview.'
26
+
27
+ # ---------------------------------------------------------------------
28
+
29
+ $.fn[pluginName] = (options) ->
30
+ args = arguments
31
+ if options is `undefined` or typeof options is "object"
32
+ @each ->
33
+ $.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
34
+
35
+ else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
36
+ returns = undefined
37
+ @each ->
38
+ instance = $.data(this, "plugin_" + pluginName)
39
+ returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
40
+ $.data this, "plugin_" + pluginName, null if options is "destroy"
41
+
42
+ (if returns isnt `undefined` then returns else this)
@@ -0,0 +1,59 @@
1
+ # https://github.com/jquery-boilerplate/jquery-boilerplate/
2
+ do ($ = jQuery, window, document) ->
3
+ pluginName = 'simple_form_markdown_editor__tabs'
4
+ defaults =
5
+ debug: false
6
+ is_active_class: '<%= SimpleFormMarkdownEditor.dom_class(:tab, :is_active) %>'
7
+
8
+ class Plugin
9
+ constructor: (@element, options) ->
10
+ @settings = $.extend {}, defaults, options
11
+
12
+ @$element = $(@element)
13
+
14
+ @_defaults = defaults
15
+ @_name = pluginName
16
+
17
+ @init()
18
+
19
+ init: ->
20
+ @set_active_tab(@get_edit_tab())
21
+
22
+ @$element.on 'click', @get_tabs().selector, (e) =>
23
+ $tab = $(e.currentTarget)
24
+ @set_active_tab($tab)
25
+
26
+ @$element.on 'click', @get_edit_tab().selector, (e) =>
27
+ @$element.trigger('show_editor')
28
+
29
+ @$element.on 'click', @get_preview_tab().selector, (e) =>
30
+ @$element.trigger('show_preview')
31
+
32
+ # ---------------------------------------------------------------------
33
+
34
+ get_edit_tab: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:tab, :edit) %>')
35
+ get_preview_tab: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:tab, :preview) %>')
36
+ get_tabs: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:tab) %>')
37
+
38
+ # ---------------------------------------------------------------------
39
+
40
+ set_active_tab: ($tab) ->
41
+ @get_tabs().removeClass(@settings.is_active_class)
42
+ $tab.addClass(@settings.is_active_class)
43
+
44
+ # ---------------------------------------------------------------------
45
+
46
+ $.fn[pluginName] = (options) ->
47
+ args = arguments
48
+ if options is `undefined` or typeof options is "object"
49
+ @each ->
50
+ $.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
51
+
52
+ else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
53
+ returns = undefined
54
+ @each ->
55
+ instance = $.data(this, "plugin_" + pluginName)
56
+ returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
57
+ $.data this, "plugin_" + pluginName, null if options is "destroy"
58
+
59
+ (if returns isnt `undefined` then returns else this)
@@ -0,0 +1,98 @@
1
+ #= require simple_form_markdown_editor/__buttons
2
+ #= require simple_form_markdown_editor/__editor
3
+ #= require simple_form_markdown_editor/__help
4
+ #= require simple_form_markdown_editor/__preview
5
+ #= require simple_form_markdown_editor/__tabs
6
+
7
+ do ($ = jQuery, window, document) ->
8
+ pluginName = 'simple_form_markdown_editor'
9
+ defaults =
10
+ debug: false
11
+ definitions: JSON.parse('<%= SimpleFormMarkdownEditor::MarkdownEditorInput.configuration.button_definitions.to_json %>')
12
+ is_editor_class: '<%= SimpleFormMarkdownEditor.dom_class(:is_editor) %>'
13
+ is_help_class: '<%= SimpleFormMarkdownEditor.dom_class(:is_help) %>'
14
+
15
+ class Plugin
16
+ constructor: (@element, options) ->
17
+ @settings = $.extend {}, defaults, options
18
+
19
+ @$element = $(@element)
20
+
21
+ @_defaults = defaults
22
+ @_name = pluginName
23
+
24
+ @init()
25
+
26
+ init: ->
27
+ @get_buttons().simple_form_markdown_editor__buttons()
28
+ @get_editor().simple_form_markdown_editor__editor()
29
+ @get_help().simple_form_markdown_editor__help()
30
+ @get_preview().simple_form_markdown_editor__preview()
31
+ @get_tabs().simple_form_markdown_editor__tabs()
32
+
33
+ @$element.on 'show_editor', (e) =>
34
+ e.stopPropagation()
35
+ @$element.addClass(@settings.is_editor_class)
36
+
37
+ @$element.on 'show_preview', (e) =>
38
+ e.stopPropagation()
39
+ @$element.removeClass(@settings.is_editor_class)
40
+
41
+ @$element.on 'show_preview', (e) =>
42
+ e.stopPropagation()
43
+ options = @get_options()
44
+ val = @get_editor().simple_form_markdown_editor__editor('get_val')
45
+ $.ajax
46
+ type: 'POST'
47
+ url: @get_preview_path()
48
+ data:
49
+ _method: 'PUT'
50
+ text: val
51
+ options: options
52
+ success: (html) =>
53
+ @get_preview().trigger(type: 'show_preview', html: html)
54
+
55
+ @$element.on 'toggle_help', (e) =>
56
+ e.stopPropagation()
57
+ @$element.toggleClass(@settings.is_help_class)
58
+
59
+ @$element.on 'execute_command', (e) =>
60
+ e.stopPropagation()
61
+ command = e.command
62
+ definition = @settings.definitions[command]
63
+ @get_editor().trigger
64
+ type: 'execute_command_definition'
65
+ command: command
66
+ definition: definition
67
+
68
+ # ---------------------------------------------------------------------
69
+
70
+ get_buttons: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:buttons) %>')
71
+ get_editor: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:editor) %>')
72
+ get_help: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:help) %>')
73
+ get_preview: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:preview) %>')
74
+ get_tabs: -> @$element.find('.<%= SimpleFormMarkdownEditor.dom_class(:tabs) %>')
75
+
76
+ get_options: -> @$element.data('options')
77
+ get_preview_path: -> @$element.data('preview-path')
78
+
79
+ # ---------------------------------------------------------------------
80
+
81
+ $.fn[pluginName] = (options) ->
82
+ args = arguments
83
+ if options is `undefined` or typeof options is "object"
84
+ @each ->
85
+ $.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
86
+
87
+ else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
88
+ returns = undefined
89
+ @each ->
90
+ instance = $.data(this, "plugin_" + pluginName)
91
+ returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
92
+ $.data this, "plugin_" + pluginName, null if options is "destroy"
93
+
94
+ (if returns isnt `undefined` then returns else this)
95
+
96
+ # =====================================================================
97
+
98
+ $ -> $('.<%= SimpleFormMarkdownEditor.dom_class %>').simple_form_markdown_editor()
@@ -1,3 +1,3 @@
1
1
  /*
2
- *= require simple_form_markdown_editor/simple_form_markdown_editor
3
- */
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,5 @@
1
+ @mixin reset-list {
2
+ margin: 0;
3
+ padding: 0;
4
+ list-style: none;
5
+ }
@@ -0,0 +1,4 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:button) %> {
4
+ }
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:button_group) %> {
4
+ display: inline-block;
5
+ }
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:button_wrapper) %> {
4
+ display: inline-block;
5
+ }
@@ -0,0 +1,9 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:buttons) %> {
4
+ .<%= SimpleFormMarkdownEditor.dom_class(:button_group) %> {
5
+ &:not(:last-child) {
6
+ margin-right: 1em;
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:editor) %> {
4
+ }
@@ -0,0 +1,4 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:header) %> {
4
+ }
@@ -0,0 +1,12 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help) %> {
4
+ }
5
+
6
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sections) %>,
7
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_sections) %>,
8
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :texts) %> {
9
+ display: inline-block;
10
+ vertical-align: top;
11
+ width: (100%/3);
12
+ }
@@ -0,0 +1,3 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :section) %> {}
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sections) %> {
4
+ @include reset-list;
5
+ }
@@ -0,0 +1,9 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_section) %> {
4
+ display: none;
5
+ }
6
+
7
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :is_active) %> {
8
+ display: block;
9
+ }
@@ -0,0 +1,7 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :item) %> {
4
+ }
5
+
6
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :item, :is_active) %> {
7
+ }
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :items) %> {
4
+ @include reset-list;
5
+ }
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :sub_sections) %> {
4
+ @include reset-list;
5
+ }
@@ -0,0 +1,9 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :text) %> {
4
+ display: none;
5
+ }
6
+
7
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :text, :is_active) %> {
8
+ display: block;
9
+ }
@@ -0,0 +1,5 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:help, :texts) %> {
4
+ @include reset-list;
5
+ }
@@ -0,0 +1,4 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:preview) %> {
4
+ }
@@ -0,0 +1,23 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class %> {
4
+ // is_editor
5
+ &.<%= SimpleFormMarkdownEditor.dom_class(:is_editor) %> {
6
+ .<%= SimpleFormMarkdownEditor.dom_class(:editor) %> { display: block; }
7
+ .<%= SimpleFormMarkdownEditor.dom_class(:preview) %> { display: none; }
8
+ }
9
+
10
+ &:not(.<%= SimpleFormMarkdownEditor.dom_class(:is_editor) %>) {
11
+ .<%= SimpleFormMarkdownEditor.dom_class(:editor) %> { display: none; }
12
+ .<%= SimpleFormMarkdownEditor.dom_class(:preview) %> { display: block; }
13
+ }
14
+
15
+ // is_help
16
+ &.<%= SimpleFormMarkdownEditor.dom_class(:is_help) %> {
17
+ .<%= SimpleFormMarkdownEditor.dom_class(:help) %> { display: block; }
18
+ }
19
+
20
+ &:not(.<%= SimpleFormMarkdownEditor.dom_class(:is_help) %>) {
21
+ .<%= SimpleFormMarkdownEditor.dom_class(:help) %> { display: none; }
22
+ }
23
+ }
@@ -0,0 +1,8 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:tab) %> {
4
+ display: inline-block;
5
+ }
6
+
7
+ .<%= SimpleFormMarkdownEditor.dom_class(:tab, :is_active) %> {
8
+ }
@@ -0,0 +1,9 @@
1
+ @import 'simple_form_markdown_editor/partials';
2
+
3
+ .<%= SimpleFormMarkdownEditor.dom_class(:tabs) %> {
4
+ .<%= SimpleFormMarkdownEditor.dom_class(:tab) %> {
5
+ &:not(:last-child) {
6
+ margin-right: 1em;
7
+ }
8
+ }
9
+ }
@@ -8,7 +8,17 @@ require 'simple_form_markdown_editor/version'
8
8
 
9
9
  require 'i18n'
10
10
 
11
- # ---------------------------------------------------------------------
11
+ module SimpleFormMarkdownEditor
12
+ def self.dom_class(*args)
13
+ prefix, alts = args.partition { |i| !i.is_a?(Array) }
14
+ prefix = ['simple_form_markdown_editor'] + prefix
15
+ return prefix.compact.join('__') if alts.empty?
16
+ alts.flatten.map do |item|
17
+ prefix += [item]
18
+ prefix.compact.join('__')
19
+ end
20
+ end
21
+ end
12
22
 
13
23
  module SimpleForm
14
24
  class FormBuilder
@@ -16,6 +26,4 @@ module SimpleForm
16
26
  end
17
27
  end
18
28
 
19
- # ---------------------------------------------------------------------
20
-
21
29
  I18n.load_path += Dir.glob(File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml'))
@@ -20,9 +20,11 @@ module SimpleFormMarkdownEditor
20
20
 
21
21
  def input(wrapper_options)
22
22
  attrs = merge_wrapper_options(input_html_options, wrapper_options)
23
+ attrs[:class] = [SimpleFormMarkdownEditor.dom_class, SimpleFormMarkdownEditor.dom_class(:is_editor)]
24
+ attrs[:class] << SimpleFormMarkdownEditor.dom_class(:is_help) if help_visible?
23
25
  attrs[:data] ||= {}
24
26
  attrs[:data][:preview_path] = preview_path
25
- attrs[:data][:options] = { render_class: render_class.to_s, render_options: render_options, extensions: extensions }
27
+ attrs[:data][:options] = { render_class: render_class, render_options: render_options, extensions: extensions }
26
28
 
27
29
  template.content_tag :div, attrs do
28
30
  template.concat header
@@ -50,12 +52,8 @@ module SimpleFormMarkdownEditor
50
52
  options.fetch(:extensions, MarkdownEditorInput.configuration.extensions)
51
53
  end
52
54
 
53
- def input_html_classes
54
- super.push('simple_form_markdown_editor')
55
- end
56
-
57
55
  def header
58
- template.content_tag :div, class: 'header' do
56
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:header) do
59
57
  tabs + buttons
60
58
  end.html_safe
61
59
  end
@@ -63,10 +61,8 @@ module SimpleFormMarkdownEditor
63
61
  # ---------------------------------------------------------------------
64
62
 
65
63
  def tabs
66
- template.content_tag :div, class: 'editor_tabs' do
67
- template.content_tag :ul, class: 'tabs' do
68
- tab_list.map { |t| tab(t) }.flatten.join.html_safe
69
- end
64
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:tabs) do
65
+ tab_list.map { |t| tab(t) }.flatten.join.html_safe
70
66
  end
71
67
  end
72
68
 
@@ -75,44 +71,32 @@ module SimpleFormMarkdownEditor
75
71
  end
76
72
 
77
73
  def tab(name)
78
- template.content_tag :li, class: ['tab', name.to_s.underscore.downcase], data: { command: name.to_s } do
79
- template.content_tag(
80
- :span,
81
- I18n.t(name.to_sym, scope: 'simple_form_markdown_editor.tabs'),
82
- class: name.to_s.underscore.downcase
83
- )
74
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class([:tab, name]) do
75
+ template.content_tag(:span, I18n.t(name, scope: 'simple_form_markdown_editor.tabs'))
84
76
  end
85
77
  end
86
78
 
87
79
  # ---------------------------------------------------------------------
88
80
 
89
81
  def buttons
90
- template.content_tag :div, class: 'buttons' do
91
- button_groups
92
- end
93
- end
94
-
95
- def button_groups
96
- template.content_tag :ul, class: 'button_groups' do
82
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:buttons) do
97
83
  button_list.map { |group| button_group(group) }.flatten.join.html_safe
98
84
  end
99
85
  end
100
86
 
101
87
  def button_group(g)
102
- template.content_tag :li, class: 'button_group', data: { buttons: g.join(' ') } do
103
- template.content_tag :ul, class: 'buttons' do
104
- g.map { |b| button(b) }.flatten.join.html_safe
105
- end
88
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:button_group), data: { buttons: g.join(' ') } do
89
+ g.map { |b| button(b) }.flatten.join.html_safe
106
90
  end
107
91
  end
108
92
 
109
93
  def button(b)
110
94
  return if b == 'help' && !help_enabled?
111
- template.content_tag :li, class: ['button', b], data: { toggle: b } do
95
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:button_wrapper) do
112
96
  template.content_tag(
113
97
  :button,
114
- I18n.t(b.to_sym, scope: 'simple_form_markdown_editor.buttons'),
115
- class: b,
98
+ I18n.t(b, scope: 'simple_form_markdown_editor.buttons'),
99
+ class: SimpleFormMarkdownEditor.dom_class(:button),
116
100
  name: '',
117
101
  role: '',
118
102
  state: '',
@@ -129,7 +113,7 @@ module SimpleFormMarkdownEditor
129
113
  # ---------------------------------------------------------------------
130
114
 
131
115
  def editor
132
- template.content_tag :div, class: %w(editor) do
116
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:editor) do
133
117
  @builder.text_area(attribute_name, input_html_options).html_safe
134
118
  end
135
119
  end
@@ -138,7 +122,7 @@ module SimpleFormMarkdownEditor
138
122
  template.content_tag(
139
123
  :div,
140
124
  I18n.t(:loading, scope: 'simple_form_markdown_editor'),
141
- class: %w(preview),
125
+ class: SimpleFormMarkdownEditor.dom_class(:preview),
142
126
  data: { nothing_to_preview_text: I18n.t(:nothing_to_preview, scope: 'simple_form_markdown_editor') }
143
127
  )
144
128
  end
@@ -147,49 +131,53 @@ module SimpleFormMarkdownEditor
147
131
 
148
132
  def help
149
133
  return unless help_enabled?
150
- template.content_tag :div, class: %w(help), data: { visible: help_visible? } do
151
- template.content_tag :div, class: %w(help_wrapper) do
152
- help_sections + help_sub_sections + help_texts
153
- end
134
+ template.content_tag :div, class: SimpleFormMarkdownEditor.dom_class(:help) do
135
+ help_sections + help_sub_sections + help_texts
154
136
  end
155
137
  end
156
138
 
157
139
  def help_sections
158
- template.content_tag :ul, class: %w(sections) do
140
+ template.content_tag :ul, class: SimpleFormMarkdownEditor.dom_class(:help, :sections) do
159
141
  i18n_help.map { |section, content| help_section(section, content) }.flatten.join.html_safe
160
142
  end
161
143
  end
162
144
 
163
145
  def help_section(section, content)
164
146
  return unless content[:title]
165
- template.content_tag :li, class: ['section', section.to_s], data: { toggle: section.to_s } do
166
- template.content_tag :span, content[:title].to_s, class: section.to_s
147
+ template.content_tag :li, class: SimpleFormMarkdownEditor.dom_class(:help, :section), data: { section: section } do
148
+ template.content_tag :a, content[:title], class: section, href: '#'
167
149
  end.html_safe
168
150
  end
169
151
 
170
152
  def help_sub_sections
171
- i18n_help.map do |section, content|
172
- template.content_tag :ul, class: ['sub_sections', section.to_s] do
173
- content[:elements].map { |sec, con| help_sub_section(sec, con) }.flatten.join.html_safe
174
- end
175
- end.flatten.join.html_safe
153
+ template.content_tag :ul, class: SimpleFormMarkdownEditor.dom_class(:help, :sub_sections) do
154
+ i18n_help.map do |section, content|
155
+ template.content_tag :li, class: SimpleFormMarkdownEditor.dom_class(:help, :sub_section), data: { section: section } do
156
+ template.content_tag :ul, class: SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :items) do
157
+ content[:elements].map { |sec, con| help_sub_section_item(sec, con) }.flatten.join.html_safe
158
+ end
159
+ end
160
+ end.flatten.join.html_safe
161
+ end
176
162
  end
177
163
 
178
- def help_sub_section(section, content)
164
+ def help_sub_section_item(sub_section, content)
179
165
  return unless content[:title]
180
- template.content_tag :li, class: ['sub_section', section.to_s], data: { toggle: section.to_s } do
181
- template.content_tag :span, content[:title].to_s, class: section.to_s
166
+ template.content_tag :li, class: SimpleFormMarkdownEditor.dom_class(:help, :sub_section, :item), data: { sub_section: sub_section } do
167
+ template.content_tag :a, content[:title], href: '#'
182
168
  end.html_safe
183
169
  end
184
170
 
185
171
  def help_texts
186
- i18n_help.map do |section, content|
187
- content[:elements].map do |el, con|
188
- template.content_tag :div, class: ['help_text', el.to_s], data: { section: section.to_s, sub_section: el.to_s } do
189
- Renderer.call(con[:text], render_class: render_class, render_options: render_options, extensions: extensions)
172
+ template.content_tag :ul, class: SimpleFormMarkdownEditor.dom_class(:help, :texts) do
173
+ i18n_help.map do |section, content|
174
+ content[:elements].map do |el, con|
175
+ template.content_tag :li, class: SimpleFormMarkdownEditor.dom_class(:help, :text), data: { section: section, sub_section: el } do
176
+ Renderer.call(con[:text], render_class: render_class, render_options: render_options, extensions: extensions)
177
+ end
190
178
  end
191
- end
192
- end.flatten.join.html_safe
179
+ end.flatten.join.html_safe
180
+ end
193
181
  end
194
182
 
195
183
  # ---------------------------------------------------------------------