action_markdown 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8c962323d1ff2acea1e7e1df96ba96ea2eebe94e2b526d03246f3f4c0390dbb
4
- data.tar.gz: b18cb4ea30a5a93c0e0c7c0c28aa65869ce82c8ad32f8fa0c72d9d32a88881ef
3
+ metadata.gz: 8a8a81aff87626aae72f69e3be289da05a2b876e9245e31431715152690d48b0
4
+ data.tar.gz: db012c37bdca4c232184ecd68b727e1eb7294c4cfaa387450990e2bb62e958ff
5
5
  SHA512:
6
- metadata.gz: 1519877f07359986e7379461440048336dd8c9154dc048c008ca05d69c43c4f594ffc7780464676f8e9efac8dace61d33c3f6af11d4864a43d99096915c8f2da
7
- data.tar.gz: d44aaeff14fbdc4396ec4b02d779c10cbab4fec3d0c1c1e9032834de78b4b49027a13bda3b017fe2e91f88ae4002bd576fd7ef4d9d810dae3e71737f6bfbe1fd
6
+ metadata.gz: 696d0b60182b7baa446ecfed938304de4673fdb406db11e21248b2cdc118951a46dcbc6f516f9d7637d59f93ceb2d97f2b0e7e165ad07374ab45b59873d69937
7
+ data.tar.gz: 9953248c9fcd4f28047b06404a619925ac752828b00981d01cded14b75ac09b4840c314035704f0d31e60bc3006729d809676354a812347410cb6af0eed94368
data/README.md CHANGED
@@ -63,6 +63,17 @@ In the view above, the Markdown content will automatically be converted to the f
63
63
  <p>This is a paragraph.</p>
64
64
  ```
65
65
 
66
+ **Note**: To use a Markdown fields in forms, we should use the `markdown_field` helper like in the following example:
67
+
68
+ ```erb
69
+ <%= form_with model: article do |f| %>
70
+ <%= f.label :content %>
71
+ <%= f.markdown_field :content %>
72
+
73
+ <%= f.submit "Save" %>
74
+ <% end %>
75
+ ```
76
+
66
77
  ## License
67
78
 
68
79
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,313 @@
1
+ .action-markdown {
2
+ /* Inline code variables */
3
+ --am-inline-code-padding-y: 0.15rem;
4
+ --am-inline-code-padding-x: 0.2rem;
5
+ --am-inline-code-border-radius: 0.375rem;
6
+ --am-inline-code-background: hsl(53 100% 65% / 0.2);
7
+
8
+ /* Code block paddings */
9
+ --am-code-padding-y: 1rem;
10
+ --am-code-padding-x: 1.5rem;
11
+
12
+ /* Code block border-radius */
13
+ --am-code-border-radius: 0.5rem;
14
+
15
+ /* Code block shadow */
16
+ --am-code-shadow: 1px 3px 6px hsl(0 0% 0% / 0.1);
17
+
18
+ /* Code syntax highlighting variables */
19
+ --am-code-background:hsl(208 95% 8%);
20
+ --am-code-comment: hsl(180 9% 43%);
21
+ --am-code-string: hsl(35 71% 74%);
22
+ --am-code-inherit: hsl(77 67% 68%);
23
+ --am-code-number: hsl(14 90% 70%);
24
+ --am-code-error: hsl(357 79% 65%);
25
+ --am-code-constant: hsl(221 100% 75%);
26
+ --am-code-keyword: hsl(276 68% 75%);
27
+ --am-code-class: hsl(33 100% 77%);
28
+ --am-code-variable: hsl(169 56% 68%);
29
+ --am-code-text: hsl(217 34% 88%);
30
+ --am-code-html: hsl(169 47% 86%);
31
+ }
32
+
33
+ .action-markdown p code,
34
+ .action-markdown li code {
35
+ color: inherit;
36
+ border-radius: var(--am-inline-code-border-radius);
37
+ background-color: var(--am-inline-code-background);
38
+ padding: var(--am-inline-code-padding-y) var(--am-inline-code-padding-x);
39
+ }
40
+
41
+ .action-markdown div.highlight {
42
+ overflow: auto;
43
+ background-color: var(--am-code-background);
44
+ border-radius: var(--am-code-border-radius);
45
+ box-shadow: var(--am-code-shadow);
46
+ }
47
+
48
+ .action-markdown pre.highlight {
49
+ margin: 0;
50
+ float: left;
51
+ padding: var(--am-code-padding-y) var(--am-code-padding-x);
52
+ }
53
+
54
+ .action-markdown .highlight code {
55
+ color: var(--am-code-text);
56
+ }
57
+
58
+ .action-markdown .highlight .cm {
59
+ color: var(--am-code-comment);
60
+ }
61
+
62
+ .action-markdown .highlight .p {
63
+ color: var(--am-code-comment);
64
+ }
65
+
66
+ .action-markdown .highlight .cp {
67
+ color: var(--am-code-error);
68
+ }
69
+
70
+ .action-markdown .highlight .c1 {
71
+ color: var(--am-code-comment);
72
+ }
73
+
74
+ .action-markdown .highlight .cs {
75
+ color: var(--am-code-comment);
76
+ }
77
+
78
+ .action-markdown .highlight .c,
79
+ .action-markdown .highlight .ch,
80
+ .action-markdown .highlight .cd,
81
+ .action-markdown .highlight .cpf {
82
+ color: var(--am-code-comment);
83
+ }
84
+
85
+ .action-markdown .highlight .err {
86
+ color: var(--am-code-keyword);
87
+ }
88
+
89
+ .action-markdown .highlight .gd {
90
+ color: var(--am-code-keyword);
91
+ }
92
+
93
+ .action-markdown .highlight .ge {
94
+ color: var(--am-code-keyword);
95
+ }
96
+
97
+ .action-markdown .highlight .gr {
98
+ color: var(--am-code-error);
99
+ }
100
+
101
+ .action-markdown .highlight .gh {
102
+ color: var(--am-code-comment);
103
+ }
104
+
105
+ .action-markdown .highlight .gi {
106
+ color: var(--am-code-keyword);
107
+ }
108
+
109
+ .action-markdown .highlight .go {
110
+ color: var(--am-code-comment);
111
+ }
112
+
113
+ .action-markdown .highlight .gp {
114
+ color: var(--am-code-comment);
115
+ }
116
+
117
+ .action-markdown .highlight .gu {
118
+ color: var(--am-code-comment);
119
+ }
120
+
121
+ .action-markdown .highlight .gt {
122
+ color: var(--am-code-error);
123
+ }
124
+ .action-markdown .highlight .kc {
125
+ color: var(--am-code-keyword);
126
+ }
127
+
128
+ .action-markdown .highlight .kd {
129
+ color: var(--am-code-keyword);
130
+ }
131
+
132
+ .action-markdown .highlight .kn {
133
+ color: var(--am-code-keyword);
134
+ }
135
+
136
+ .action-markdown .highlight .kp {
137
+ color: var(--am-code-keyword);
138
+ }
139
+
140
+ .action-markdown .highlight .kr {
141
+ color: var(--am-code-keyword);
142
+ }
143
+
144
+ .action-markdown .highlight .kt {
145
+ color: var(--am-code-class);
146
+ }
147
+
148
+ .action-markdown .highlight .k,
149
+ .action-markdown .highlight .kv {
150
+ color: var(--am-code-keyword);
151
+ }
152
+
153
+ .action-markdown .highlight .mf {
154
+ color: var(--am-code-number);
155
+ }
156
+
157
+ .action-markdown .highlight .mh {
158
+ color: var(--am-code-number);
159
+ }
160
+
161
+ .action-markdown .highlight .il {
162
+ color: var(--am-code-number);
163
+ }
164
+
165
+ .action-markdown .highlight .mi {
166
+ color: var(--am-code-number);
167
+ }
168
+
169
+ .action-markdown .highlight .mo {
170
+ color: var(--am-code-number);
171
+ }
172
+
173
+ .action-markdown .highlight .m,
174
+ .action-markdown .highlight .mb,
175
+ .action-markdown .highlight .mx {
176
+ color: var(--am-code-number);
177
+ }
178
+
179
+ .action-markdown .highlight .sa {
180
+ color: var(--am-code-keyword);
181
+ }
182
+
183
+ .action-markdown .highlight .sb {
184
+ color: var(--am-code-string);
185
+ }
186
+
187
+ .action-markdown .highlight .sc {
188
+ color: var(--am-code-string);
189
+ }
190
+
191
+ .action-markdown .highlight .sd {
192
+ color: var(--am-code-string);
193
+ }
194
+
195
+ .action-markdown .highlight .s2 {
196
+ color: var(--am-code-string);
197
+ }
198
+
199
+ .action-markdown .highlight .se {
200
+ color: var(--am-code-string);
201
+ }
202
+
203
+ .action-markdown .highlight .sh {
204
+ color: var(--am-code-string);
205
+ }
206
+
207
+ .action-markdown .highlight .si {
208
+ color: var(--am-code-string);
209
+ }
210
+
211
+ .action-markdown .highlight .sx {
212
+ color: var(--am-code-string);
213
+ }
214
+
215
+ .action-markdown .highlight .sr {
216
+ color: var(--am-code-inherit);
217
+ }
218
+
219
+ .action-markdown .highlight .s1 {
220
+ color: var(--am-code-string);
221
+ }
222
+
223
+ .action-markdown .highlight .ss {
224
+ color: var(--am-code-variable);
225
+ }
226
+
227
+ .action-markdown .highlight .s,
228
+ .action-markdown .highlight .dl {
229
+ color: var(--am-code-string);
230
+ }
231
+
232
+ .action-markdown .highlight .na {
233
+ color: var(--am-code-inherit);
234
+ }
235
+
236
+ .action-markdown .highlight .bp {
237
+ color: var(--am-code-comment);
238
+ }
239
+
240
+ .action-markdown .highlight .nb {
241
+ color: var(--am-code-text);
242
+ }
243
+
244
+ .action-markdown .highlight .nc {
245
+ color: var(--am-code-class);
246
+ }
247
+
248
+ .action-markdown .highlight .no {
249
+ color: var(--am-code-inherit);
250
+ }
251
+
252
+ .action-markdown .highlight .nd {
253
+ color: var(--am-code-keyword);
254
+ }
255
+
256
+ .action-markdown .highlight .ni {
257
+ color: var(--am-code-constant);
258
+ }
259
+
260
+ .action-markdown .highlight .ne {
261
+ color: var(--am-code-constant);
262
+ }
263
+
264
+ .action-markdown .highlight .nf,
265
+ .action-markdown .highlight .fm {
266
+ color: var(--am-code-constant);
267
+ }
268
+
269
+ .action-markdown .highlight .nl {
270
+ color: var(--am-code-constant);
271
+ }
272
+
273
+ .action-markdown .highlight .nn {
274
+ color: var(--am-code-inherit);
275
+ }
276
+
277
+ .action-markdown .highlight .nt {
278
+ color: var(--am-code-html);
279
+ }
280
+
281
+ .action-markdown .highlight .n,
282
+ .action-markdown .highlight .p {
283
+ color: var(--am-code-text);
284
+ }
285
+
286
+ .action-markdown .highlight .vc {
287
+ color: var(--am-code-inherit);
288
+ }
289
+
290
+ .action-markdown .highlight .vg {
291
+ color: var(--am-code-inherit);
292
+ }
293
+
294
+ .action-markdown .highlight .vi {
295
+ color: var(--am-code-inherit);
296
+ }
297
+
298
+ .action-markdown .highlight .nv,
299
+ .action-markdown .highlight .vm {
300
+ color: var(--am-code-inherit);
301
+ }
302
+
303
+ .action-markdown .highlight .ow {
304
+ color: var(--am-code-keyword);
305
+ }
306
+
307
+ .action-markdown .highlight .o {
308
+ color: var(--am-code-keyword);
309
+ }
310
+
311
+ .action-markdown .highlight .w {
312
+ color: var(--am-code-comment);
313
+ }
@@ -0,0 +1,37 @@
1
+ require "action_view/helpers/tags/placeholderable"
2
+
3
+ module ActionMarkdown
4
+ module TagHelper
5
+ def markdown_field_tag(name, value = nil, options = {})
6
+ options = options.symbolize_keys
7
+
8
+ content_tag("textarea", value, options)
9
+ end
10
+ end
11
+ end
12
+
13
+ module ActionView::Helpers
14
+ class Tags::ActionMarkdown < Tags::Base
15
+ include Tags::Placeholderable
16
+
17
+ def render
18
+ options = @options.stringify_keys
19
+ options["value"] = options.fetch("value") { value&.to_markdown }
20
+ add_default_name_and_id(options)
21
+
22
+ @template_object.markdown_field_tag("textarea", options["value"], options.except("value"))
23
+ end
24
+ end
25
+
26
+ module FormHelper
27
+ def markdown_field(object_name, method, options = {})
28
+ Tags::ActionMarkdown.new(object_name, method, self, options).render
29
+ end
30
+ end
31
+
32
+ class FormBuilder
33
+ def markdown_field(method, options = {})
34
+ @template.markdown_field(@object_name, method, objectify_options(options))
35
+ end
36
+ end
37
+ end
@@ -7,6 +7,7 @@ module ActionMarkdown
7
7
  belongs_to :record, polymorphic: true, touch: true
8
8
 
9
9
  delegate :to_s, :nil?, to: :body
10
+ delegate :to_markdown, to: :body, allow_nil: true
10
11
  delegate :blank?, :empty?, :present?, to: :to_html
11
12
 
12
13
  def to_html
@@ -1 +1,3 @@
1
- <%= sanitize content.to_html %>
1
+ <div class="action-markdown">
2
+ <%= sanitize content.to_html %>
3
+ </div>
@@ -6,6 +6,10 @@ module ActionMarkdown
6
6
  @body = body
7
7
  end
8
8
 
9
+ def to_markdown
10
+ body
11
+ end
12
+
9
13
  def to_html
10
14
  markdown_renderer.render(body)
11
15
  end
@@ -7,5 +7,11 @@ module ActionMarkdown
7
7
  extend ActionMarkdown::Attribute
8
8
  end
9
9
  end
10
+
11
+ initializer "action_markdown.helper" do
12
+ ActiveSupport.on_load(:action_controller_base) do
13
+ helper ActionMarkdown::Engine.helpers
14
+ end
15
+ end
10
16
  end
11
17
  end
@@ -14,11 +14,11 @@ module ActionMarkdown
14
14
  when nil
15
15
  nil
16
16
  when self
17
- content.to_html
17
+ content.to_markdown
18
18
  when ActionMarkdown::MarkdownText
19
- content.body.to_html
19
+ content.body.to_markdown
20
20
  else
21
- new(content).to_html
21
+ new(content).to_markdown
22
22
  end
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module ActionMarkdown
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -2,6 +2,7 @@ require "action_markdown/version"
2
2
  require "action_markdown/engine"
3
3
 
4
4
  require "redcarpet"
5
+ require "rouge"
5
6
 
6
7
  module ActionMarkdown
7
8
  extend ActiveSupport::Autoload
@@ -1,9 +1,23 @@
1
1
  module ActionMarkdown
2
2
  module Generators
3
3
  class InstallGenerator < ::Rails::Generators::Base
4
+ source_root ActionMarkdown::Engine.root
5
+
4
6
  def create_migrations
5
7
  rails_command "railties:install:migrations FROM=action_markdown", inline: true
6
8
  end
9
+
10
+ def create_action_markdown_files
11
+ copy_file(
12
+ "app/assets/stylesheets/action_markdown/action_markdown.css",
13
+ "app/assets/stylesheets/action_markdown.css"
14
+ )
15
+
16
+ copy_file(
17
+ "app/views/action_markdown/contents/_content.html.erb",
18
+ "app/views/action_markdown/contents/_content.html.erb"
19
+ )
20
+ end
7
21
  end
8
22
  end
9
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Ruban
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2022-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,6 +61,8 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - MIT-LICENSE
63
63
  - README.md
64
+ - app/assets/stylesheets/action_markdown/action_markdown.css
65
+ - app/helpers/action_markdown/tag_helper.rb
64
66
  - app/models/action_markdown/application_record.rb
65
67
  - app/models/action_markdown/markdown_text.rb
66
68
  - app/views/action_markdown/contents/_content.html.erb