action_markdown 0.1.2 → 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: 914e4bf003d2d90a96ceb63bd26cb06aad85f3d0f071eaaefaacbbfc49eb1628
4
- data.tar.gz: 7b65f6e453de6c04b24bcbaff52bb98cc6550e461e52951e383b364d5c18a0da
3
+ metadata.gz: 8a8a81aff87626aae72f69e3be289da05a2b876e9245e31431715152690d48b0
4
+ data.tar.gz: db012c37bdca4c232184ecd68b727e1eb7294c4cfaa387450990e2bb62e958ff
5
5
  SHA512:
6
- metadata.gz: 0b40284e3ea4ab89c47a407457a832fa76338bd1ab89310556e9e5eda5c15689d4b8dd11c68f32925ab86ec5681907f7c7948c67bb7658e393758e7ecab80ac6
7
- data.tar.gz: 319d898b6af736bf7e391030117ec456ea3d9ae7c2fbb71f021e3bdd947eb125b85d6a26db39b12aab9f745f708c9a3d3708f17289b10206bf3c2ff3bf852dd4
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,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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActionMarkdown
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  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.2
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-29 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
@@ -62,6 +62,7 @@ files:
62
62
  - MIT-LICENSE
63
63
  - README.md
64
64
  - app/assets/stylesheets/action_markdown/action_markdown.css
65
+ - app/helpers/action_markdown/tag_helper.rb
65
66
  - app/models/action_markdown/application_record.rb
66
67
  - app/models/action_markdown/markdown_text.rb
67
68
  - app/views/action_markdown/contents/_content.html.erb