simple_form_markdown_editor 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/simple_form_markdown_editor/previews_controller.rb +14 -3
- data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_tabs.js.coffee +2 -0
- data/lib/simple_form_markdown_editor/markdown_editor_input.rb +29 -10
- data/lib/simple_form_markdown_editor/renderer.rb +7 -9
- data/lib/simple_form_markdown_editor/version.rb +1 -1
- data/test/dummy/Gemfile.lock +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 592ee458505ff3dbaf28900e7c629e63d9695ec6
|
4
|
+
data.tar.gz: 41bdfbdcbb2efd2c69652d2430d868ffec19ff03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a449ac9392d44f7a34cd1ac5347bf2f25af67e9d5914b2fdeb4fd7d24b860d804239832bd3ed36064ccc2aa6ed111042d930c5c573561dc8f432fa23edb12e5
|
7
|
+
data.tar.gz: a4a14137fc0ebd75c7e85d2b49a2ca2751696721a68ed96283dd738182b1592f8ec83b5d41848c2ffffe77eb40232ffd73f6d4fe27d44738276149cf2e755c41
|
data/Gemfile.lock
CHANGED
@@ -13,12 +13,23 @@ module SimpleFormMarkdownEditor
|
|
13
13
|
|
14
14
|
# overwrite this in your own controller
|
15
15
|
def text_preview
|
16
|
-
Renderer.call(
|
16
|
+
Renderer.call(text, { render_class: render_class, extensions: extensions })
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
return unless params[:text].present?
|
19
|
+
def text
|
21
20
|
params.require(:text)
|
22
21
|
end
|
22
|
+
|
23
|
+
def options
|
24
|
+
params.fetch(:options, {})
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_class
|
28
|
+
options.fetch(:render_class, nil).to_s.safe_constantize
|
29
|
+
end
|
30
|
+
|
31
|
+
def extensions
|
32
|
+
options.fetch(:extensions, {})
|
33
|
+
end
|
23
34
|
end
|
24
35
|
end
|
data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_tabs.js.coffee
CHANGED
@@ -36,6 +36,7 @@ do ($ = jQuery, window, document) ->
|
|
36
36
|
data:
|
37
37
|
_method: 'PUT'
|
38
38
|
text: @get_textarea().val() || ''
|
39
|
+
options: @get_textarea_options()
|
39
40
|
success: (html) =>
|
40
41
|
@get_preview_div().html(html) or "<p>#{@get_nothing_to_preview_text()}</p>"
|
41
42
|
)
|
@@ -51,6 +52,7 @@ do ($ = jQuery, window, document) ->
|
|
51
52
|
get_preview_tab: -> @get_tab_lis().filter('.preview')
|
52
53
|
get_edit_tab: -> @get_tab_lis().filter('.edit')
|
53
54
|
get_nothing_to_preview_text: -> @get_preview_div().data('nothing-to-preview-text') or "Nothing to preview."
|
55
|
+
get_textarea_options: -> @$element.data('options')
|
54
56
|
|
55
57
|
# ---------------------------------------------------------------------
|
56
58
|
|
@@ -19,7 +19,12 @@ module SimpleFormMarkdownEditor
|
|
19
19
|
# =====================================================================
|
20
20
|
|
21
21
|
def input(wrapper_options)
|
22
|
-
|
22
|
+
attrs = merge_wrapper_options(input_html_options, wrapper_options)
|
23
|
+
attrs[:data] ||= {}
|
24
|
+
attrs[:data][:preview_path] = preview_path
|
25
|
+
attrs[:data][:options] = { render_class: render_class.to_s, render_options: render_options, extensions: extensions }
|
26
|
+
|
27
|
+
template.content_tag :div, attrs do
|
23
28
|
template.concat header
|
24
29
|
template.concat help
|
25
30
|
template.concat editor
|
@@ -29,10 +34,8 @@ module SimpleFormMarkdownEditor
|
|
29
34
|
|
30
35
|
private # =============================================================
|
31
36
|
|
32
|
-
def
|
33
|
-
|
34
|
-
super[:data][:preview_path] = options.fetch(:route, MarkdownEditorInput.configuration.route)
|
35
|
-
super
|
37
|
+
def preview_path
|
38
|
+
options.fetch(:route, MarkdownEditorInput.configuration.route)
|
36
39
|
end
|
37
40
|
|
38
41
|
def render_class
|
@@ -73,9 +76,11 @@ module SimpleFormMarkdownEditor
|
|
73
76
|
|
74
77
|
def tab(name)
|
75
78
|
template.content_tag :li, class: ['tab', name.to_s.underscore.downcase], data: { command: name.to_s } do
|
76
|
-
template.content_tag
|
77
|
-
|
78
|
-
|
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
|
+
)
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
@@ -104,7 +109,16 @@ module SimpleFormMarkdownEditor
|
|
104
109
|
def button(b)
|
105
110
|
return if b == 'help' && !help_enabled?
|
106
111
|
template.content_tag :li, class: ['button', b], data: { toggle: b } do
|
107
|
-
template.content_tag
|
112
|
+
template.content_tag(
|
113
|
+
:button,
|
114
|
+
I18n.t(b.to_sym, scope: 'simple_form_markdown_editor.buttons'),
|
115
|
+
class: b,
|
116
|
+
name: '',
|
117
|
+
role: '',
|
118
|
+
state: '',
|
119
|
+
type: 'button',
|
120
|
+
value: b
|
121
|
+
)
|
108
122
|
end
|
109
123
|
end
|
110
124
|
|
@@ -121,7 +135,12 @@ module SimpleFormMarkdownEditor
|
|
121
135
|
end
|
122
136
|
|
123
137
|
def preview
|
124
|
-
template.content_tag
|
138
|
+
template.content_tag(
|
139
|
+
:div,
|
140
|
+
I18n.t(:loading, scope: 'simple_form_markdown_editor'),
|
141
|
+
class: %w(preview),
|
142
|
+
data: { nothing_to_preview_text: I18n.t(:nothing_to_preview, scope: 'simple_form_markdown_editor') }
|
143
|
+
)
|
125
144
|
end
|
126
145
|
|
127
146
|
# ---------------------------------------------------------------------
|
@@ -6,20 +6,20 @@ module SimpleFormMarkdownEditor
|
|
6
6
|
new(*args).call
|
7
7
|
end
|
8
8
|
|
9
|
-
def options
|
10
|
-
|
9
|
+
def initialize(str, options = {})
|
10
|
+
super(str, options)
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_class
|
14
|
-
|
14
|
+
options.fetch(:render_class, MarkdownEditorInput.configuration.render_class)
|
15
15
|
end
|
16
16
|
|
17
17
|
def render_options
|
18
|
-
|
18
|
+
options.fetch(:render_options, MarkdownEditorInput.configuration.render_options)
|
19
19
|
end
|
20
20
|
|
21
21
|
def extensions
|
22
|
-
|
22
|
+
options.fetch(:extensions, MarkdownEditorInput.configuration.extensions)
|
23
23
|
end
|
24
24
|
|
25
25
|
def call
|
@@ -27,12 +27,10 @@ module SimpleFormMarkdownEditor
|
|
27
27
|
markdown_renderer.render(str).html_safe
|
28
28
|
end
|
29
29
|
|
30
|
-
private
|
30
|
+
private
|
31
31
|
|
32
32
|
def markdown_renderer
|
33
|
-
Redcarpet::Markdown.new(
|
34
|
-
render_class.new(render_options), extensions
|
35
|
-
)
|
33
|
+
Redcarpet::Markdown.new(render_class.new(render_options), extensions)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/test/dummy/Gemfile.lock
CHANGED