administrate-field-simple_markdown 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea65b330bfc90ed67ddebd52792aa35677d118897e3fc8039fabbb33345d569a
4
- data.tar.gz: 862990f4e3fd39fd8e8b847bf544a8c5b2a00b9fd43eb2cf9fc3c1f352fdfcd8
3
+ metadata.gz: d2eb8e3791682a9c8ebfa4967f0e853c6d4875b678675acb67eea86dcd7dceba
4
+ data.tar.gz: 6d439e41a59a99b78bd4cf0e58d9fddc43bf7c7550a55cee3c7d3a915060e8be
5
5
  SHA512:
6
- metadata.gz: e134006dcec0a45b9c8962b2c0e3d8f6e916813212f9161fbd5a135d07e98e500f8fabae606f1d0340510a5ae991fe2a60e406128bddf4a5847f9fff34f78d08
7
- data.tar.gz: edad0e340c8f5caf23e70776b799b61e0818304db7b563170f62f7158a1196c5c26dda59518f87b7f88c59b4c4556918888ba3d339f669682865d8c44a95676c
6
+ metadata.gz: 7fb9d32e21980be21f2fe19b0ca5fafc24f501e49b1f7a302b97b2fdc19e1b487bb7c4c054d13605d0fdc20b969cd86dc964a7ebd05dc947444add910eb4e778
7
+ data.tar.gz: 1b38caab72506dfaa6bc0dcb82ba5425c3a3b93fe8a5b5dc1336a1d64486306ffeee9fc95ff4fc401d8c6feb26f135485c533e8e811eb76afe482159a5508de8
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.2.0](https://github.com/zooppa/administrate-field-simple_markdown/tree/v0.2.1) (2019-01-15)
3
+ ## [v0.3.0](https://github.com/zooppa/administrate-field-simple_markdown/tree/v0.3.0) (2020-03-16)
4
+
5
+ [Full Changelog](https://github.com/zooppa/administrate-field-simple_markdown/compare/v0.2.1...v0.3.0)
6
+
7
+ * Support namespaced models and injected fields (thanks @sedubois)
8
+ * Add support for Redcarpet options (thanks @casaper)
9
+
10
+
11
+ ## [v0.2.1](https://github.com/zooppa/administrate-field-simple_markdown/tree/v0.2.1) (2019-01-15)
4
12
 
5
13
  [Full Changelog](https://github.com/zooppa/administrate-field-simple_markdown/compare/v0.2.0...v0.2.1)
6
14
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ A plugin to edit Markdown text in [Administrate] using [SimpleMDE] v1.11.2.
12
12
  Add it to your `Gemfile`:
13
13
 
14
14
  ```ruby
15
- gem 'administrate-field-simple_markdown', '~> 0.2.1'
15
+ gem 'administrate-field-simple_markdown', '~> 0.3.0'
16
16
  ```
17
17
 
18
18
  Run:
@@ -25,7 +25,19 @@ Add to your `FooDashboard`:
25
25
 
26
26
  ```ruby
27
27
  ATTRIBUTE_TYPES = {
28
- bar: Field::SimpleMarkdown
28
+ bar: Field::SimpleMarkdown.with_options({
29
+ safe_links_only: true,
30
+ filter_html: true,
31
+ with_toc_data: true,
32
+ hard_wrap: true,
33
+ link_attributes: { rel: 'follow' },
34
+ autolink: true,
35
+ tables: true,
36
+ no_intra_emphasis: true,
37
+ strikethrough: true,
38
+ highlight: true,
39
+ space_after_headers: true
40
+ })
29
41
  }.freeze
30
42
  ```
31
43
 
@@ -36,5 +48,5 @@ Administrate::Field::SimpleMarkdown is maintained by [Zooppa].
36
48
  See also the list of [contributors](https://github.com/zooppa/administrate-field-simple_markdown/contributors) who participated in this project.
37
49
 
38
50
  [administrate]: https://github.com/thoughtbot/administrate
39
- [simplemde]: https://github.com/NextStepWebs/simplemde-markdown-editor
51
+ [simplemde]: https://github.com/sparksuite/simplemde-markdown-editor
40
52
  [zooppa]: https://www.zooppa.com/
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'administrate-field-simple_markdown'
5
- gem.version = '0.2.1'
5
+ gem.version = '0.3.0'
6
6
  gem.authors = ['Zooppa']
7
7
  gem.email = ['dev@zooppa.com']
8
8
  gem.homepage = 'https://github.com/zooppa/administrate-field-simple_markdown'
@@ -1 +1,34 @@
1
1
  //= require simplemde.min
2
+
3
+ document.addEventListener('DOMContentLoaded', setup);
4
+ document.addEventListener('turbolinks:load', setup);
5
+
6
+ function setup() {
7
+ initSimpleMDE(document);
8
+ initObserver(document.querySelector('.field-unit--nested'));
9
+ }
10
+
11
+ function initSimpleMDE(element) {
12
+ if (!element) return;
13
+
14
+ element.querySelectorAll('[data-simplemde="false"]').forEach(function(el) {
15
+ new SimpleMDE({ element: el });
16
+ el.setAttribute('data-simplemde', true);
17
+ });
18
+ }
19
+
20
+ function initObserver(element) {
21
+ if (!element) return;
22
+
23
+ const observer = new MutationObserver(function (mutations) {
24
+ for (let mutation of mutations) {
25
+ if (mutation.addedNodes.length) {
26
+ mutation.addedNodes.forEach(function(node) {
27
+ initSimpleMDE(node);
28
+ });
29
+ }
30
+ }
31
+ });
32
+
33
+ observer.observe(element, { childList: true });
34
+ }
@@ -15,14 +15,5 @@ This partial renders a WYSIWYG text area to help writing Markdown text
15
15
  <%= f.label field.attribute %>
16
16
  </div>
17
17
  <div class="field-unit__field simple_markdown">
18
- <%= f.text_area field.attribute %>
18
+ <%= f.text_area field.attribute, data: { simplemde: false } %>
19
19
  </div>
20
- <%= content_for :javascript do %>
21
- <script type="text/javascript">
22
- $(function() {
23
- new SimpleMDE({
24
- element: document.getElementById('<%= f.object.class.name.underscore %>_<%= field.attribute %>')
25
- });
26
- });
27
- </script>
28
- <% end %>
@@ -28,11 +28,11 @@ module Administrate
28
28
 
29
29
  def html_renderer
30
30
  @html_renderer ||= Redcarpet::Render::HTML.new({
31
- safe_links_only: true,
32
- filter_html: true,
33
- with_toc_data: true,
34
- hard_wrap: true,
35
- link_attributes: { rel: 'nofollow' }
31
+ safe_links_only: options.fetch(:safe_links_only, true),
32
+ filter_html: options.fetch(:filter_html, true),
33
+ with_toc_data: options.fetch(:with_toc_data, true),
34
+ hard_wrap: options.fetch(:hard_wrap, true),
35
+ link_attributes: options.fetch(:link_attributes, { rel: 'nofollow' })
36
36
  })
37
37
  end
38
38
 
@@ -42,12 +42,12 @@ module Administrate
42
42
 
43
43
  def markdown(renderer)
44
44
  @markdown ||= Redcarpet::Markdown.new(renderer, {
45
- autolink: true,
46
- tables: true,
47
- no_intra_emphasis: true,
48
- strikethrough: true,
49
- highlight: true,
50
- space_after_headers: true
45
+ autolink: options.fetch(:autolink, true),
46
+ tables: options.fetch(:tables, true),
47
+ no_intra_emphasis: options.fetch(:no_intra_emphasis, true),
48
+ strikethrough: options.fetch(:strikethrough, true),
49
+ highlight: options.fetch(:highlight, true),
50
+ space_after_headers: options.fetch(:space_after_headers, true)
51
51
  })
52
52
  end
53
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-simple_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zooppa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate