simple_form_markdown_editor 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: b03c19798f5c25ab432efde17d50c3d8959d782e
4
- data.tar.gz: b0eee2af8b50d35f13265a6b3cb5734df53bf9d2
3
+ metadata.gz: 6a56989779d97f943e8bf677fc7fcffd2c50574e
4
+ data.tar.gz: ec258800ffbae843e3062b2287273e8a5057128c
5
5
  SHA512:
6
- metadata.gz: dd50158f19395babcbf5d78affc1ba073314fd4a5637bf58b81b055d42a8cede7897d858c35f254803f01c532fa23cb6ddff3e8763490963db7051ec6b0a558e
7
- data.tar.gz: 8e99ebceef0edcf61232b46551cbba4b0403e427e9d2244975941c6d7918999c67e745611abbc9b4a7faba2723bfd2d50572ffc06f9d3ac091e08c5360e4b220
6
+ metadata.gz: bfa440a693ee7d95f58b0ede31cbb46812b8b39902e9c0b8c0bf77646a9d3de75b5fc692562e6a6454106e36b75913255af32847cbd1789cea3a6188023cf59c
7
+ data.tar.gz: 5712c6b67647783cb5022901fbf9a1b8e3b6efe9c265129f5daed7e8748ee30688224afe176e1378cfa0a5a8e1465249f28ab8ec41c0e0e76213210096962106
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_markdown_editor (0.0.3)
4
+ simple_form_markdown_editor (0.0.4)
5
5
  rails (>= 4.2)
6
6
  redcarpet
7
7
  simple_form (>= 3.0.2)
@@ -94,7 +94,7 @@ GEM
94
94
  activemodel (~> 4.0)
95
95
  sprockets (3.3.4)
96
96
  rack (~> 1.0)
97
- sprockets-rails (2.3.2)
97
+ sprockets-rails (2.3.3)
98
98
  actionpack (>= 3.0)
99
99
  activesupport (>= 3.0)
100
100
  sprockets (>= 2.8, < 4.0)
data/README.md CHANGED
@@ -60,13 +60,14 @@ SimpleFormMarkdownEditor::MarkdownEditorInput.configure do |c|
60
60
  no_images: true,
61
61
  no_links: true
62
62
  }
63
+ c.route = '/custom/preview'
63
64
  end
64
65
  ```
65
66
 
66
67
  ### Input
67
68
 
68
69
  ```ruby
69
- = f.input :markdown, as: :markdown_editor, help: { enabled: true, visible: false }, buttons: [ %w(h1 h2), %w(a img) ]
70
+ = f.input :markdown, as: :markdown_editor, help: { enabled: true, visible: false }, buttons: [ %w(h1 h2), %w(a img) ], route: '/custom/preview'
70
71
  ```
71
72
 
72
73
  ## Internationalization
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -1,22 +1,24 @@
1
1
  module SimpleFormMarkdownEditor
2
2
  class PreviewsController < ActionController::Base
3
-
4
3
  protect_from_forgery with: :exception
5
-
6
4
  respond_to :html
7
5
 
8
6
  def preview
9
7
  respond_to do |format|
10
- format.html { render text: SimpleFormMarkdownEditor::Renderer.call(preview_params) }
8
+ format.html { render text: text_preview }
11
9
  end
12
10
  end
13
11
 
14
12
  private # =============================================================
15
13
 
14
+ # overwrite this in your own controller
15
+ def text_preview
16
+ Renderer.call(preview_params)
17
+ end
18
+
16
19
  def preview_params
17
20
  return unless params[:text].present?
18
21
  params.require(:text)
19
22
  end
20
-
21
23
  end
22
24
  end
@@ -32,7 +32,7 @@ do ($ = jQuery, window, document) ->
32
32
  $.ajax(
33
33
  context: @element
34
34
  type: 'POST'
35
- url: @$element.attr('data-preview-url')
35
+ url: @$element.attr('data-preview-path')
36
36
  data:
37
37
  _method: 'PUT'
38
38
  text: @get_textarea().val() || ''
@@ -1,26 +1,46 @@
1
1
  module SimpleFormMarkdownEditor
2
2
  class Configuration
3
-
4
3
  attr_accessor :buttons
5
4
  attr_accessor :extensions
6
5
  attr_accessor :help
7
6
  attr_accessor :render_options
7
+ attr_accessor :route
8
8
 
9
- def initialize
10
- @buttons = [%w(h1 h2 h3), %w(a img), %w(strong em code), %w(ul ol blockquote hr), %w(help)]
11
- @help = {
12
- enabled: true,
13
- visible: false
14
- }
15
- @extensions = {
9
+ # =====================================================================
10
+
11
+ def buttons
12
+ @buttons ||= [
13
+ %w(h1 h2 h3),
14
+ %w(a img),
15
+ %w(strong em code),
16
+ %w(ul ol blockquote hr),
17
+ %w(help)
18
+ ]
19
+ end
20
+
21
+ def extensions
22
+ @extensions ||= {
16
23
  footnotes: true,
17
24
  highlight: true,
18
25
  space_after_headers: true,
19
26
  strikethrough: true,
20
27
  superscript: true
21
28
  }
22
- @render_options = {}
23
29
  end
24
30
 
31
+ def help
32
+ @help ||= {
33
+ enabled: true,
34
+ visible: false
35
+ }
36
+ end
37
+
38
+ def render_options
39
+ @render_options ||= {}
40
+ end
41
+
42
+ def route
43
+ @route ||= Engine.routes.url_helpers.preview_path
44
+ end
25
45
  end
26
- end
46
+ end
@@ -3,7 +3,6 @@ require 'i18n'
3
3
 
4
4
  module SimpleFormMarkdownEditor
5
5
  class MarkdownEditorInput < SimpleForm::Inputs::Base
6
-
7
6
  class << self
8
7
  attr_accessor :configuration
9
8
 
@@ -31,7 +30,19 @@ module SimpleFormMarkdownEditor
31
30
  private # =============================================================
32
31
 
33
32
  def input_html_options
34
- super.merge!(data: { preview_url: SimpleFormMarkdownEditor::Engine.routes.url_helpers.preview_path })
33
+ super.merge(
34
+ data: {
35
+ preview_path: options.fetch(:route, MarkdownEditorInput.configuration.route)
36
+ }
37
+ )
38
+ end
39
+
40
+ def render_options
41
+ options.fetch(:render_options, MarkdownEditorInput.configuration.render_options)
42
+ end
43
+
44
+ def extensions
45
+ options.fetch(:extensions, MarkdownEditorInput.configuration.extensions)
35
46
  end
36
47
 
37
48
  def input_html_classes
@@ -60,7 +71,9 @@ module SimpleFormMarkdownEditor
60
71
 
61
72
  def tab name
62
73
  template.content_tag :li, class: ['tab', name.to_s.underscore.downcase], data: { command: name.to_s } do
63
- template.content_tag :span, I18n.t(name.to_sym, scope: 'simple_form_markdown_editor.tabs'), class: name.to_s.underscore.downcase
74
+ template.content_tag :span,
75
+ I18n.t(name.to_sym, scope: 'simple_form_markdown_editor.tabs'),
76
+ class: name.to_s.underscore.downcase
64
77
  end
65
78
  end
66
79
 
@@ -94,7 +107,7 @@ module SimpleFormMarkdownEditor
94
107
  end
95
108
 
96
109
  def button_list
97
- options[:buttons].presence || SimpleFormMarkdownEditor::MarkdownEditorInput.configuration.buttons
110
+ options[:buttons].presence || MarkdownEditorInput.configuration.buttons
98
111
  end
99
112
 
100
113
  # ---------------------------------------------------------------------
@@ -152,7 +165,7 @@ module SimpleFormMarkdownEditor
152
165
  i18n_help.map do |section, content|
153
166
  content[:elements].map do |element, content|
154
167
  template.content_tag :div, class: ['help_text', element.to_s], data: { section: section.to_s, sub_section: element.to_s } do
155
- SimpleFormMarkdownEditor::Renderer.call(content[:text])
168
+ Renderer.call(content[:text], { render_options: render_options, extensions: extensions })
156
169
  end
157
170
  end
158
171
  end.flatten.join.html_safe
@@ -166,7 +179,7 @@ module SimpleFormMarkdownEditor
166
179
 
167
180
  def help_enabled?
168
181
  enabled_in_options = options.fetch(:help, {}).fetch(:enabled, nil)
169
- enabled_in_config = SimpleFormMarkdownEditor::MarkdownEditorInput.configuration.help.fetch(:enabled, false)
182
+ enabled_in_config = MarkdownEditorInput.configuration.help.fetch(:enabled, false)
170
183
 
171
184
  return enabled_in_config if enabled_in_options.nil?
172
185
 
@@ -175,12 +188,11 @@ module SimpleFormMarkdownEditor
175
188
 
176
189
  def help_visible?
177
190
  visible_in_options = options.fetch(:help, {}).fetch(:visible, nil)
178
- visible_in_config = SimpleFormMarkdownEditor::MarkdownEditorInput.configuration.help.fetch(:visible, false)
191
+ visible_in_config = MarkdownEditorInput.configuration.help.fetch(:visible, false)
179
192
 
180
193
  return visible_in_config if visible_in_options.nil?
181
194
 
182
195
  visible_in_options
183
196
  end
184
-
185
197
  end
186
- end
198
+ end
@@ -1,51 +1,34 @@
1
1
  require 'redcarpet'
2
2
 
3
3
  module SimpleFormMarkdownEditor
4
- class Renderer
5
-
4
+ class Renderer < Struct.new :str, :options
6
5
  def self.call(*args)
7
6
  new(*args).call
8
7
  end
9
8
 
10
- # =====================================================================
9
+ def options
10
+ @options ||= {}
11
+ end
11
12
 
12
- attr_reader :str
13
+ def render_options
14
+ @render_options ||= options.fetch(:render_options, MarkdownEditorInput.configuration.render_options)
15
+ end
13
16
 
14
- def initialize str
15
- @str = str
17
+ def extensions
18
+ @extensions ||= options.fetch(:extensions, MarkdownEditorInput.configuration.extensions)
16
19
  end
17
20
 
18
21
  def call
19
- return unless @str.present?
20
- markdown_renderer.render(@str).html_safe
22
+ return unless str.present?
23
+ markdown_renderer.render(str).html_safe
21
24
  end
22
25
 
23
26
  private # =============================================================
24
27
 
25
28
  def markdown_renderer
26
29
  Redcarpet::Markdown.new(
27
- Redcarpet::Render::HTML.new(self.class.configuration.render_options),
28
- self.class.configuration.extensions
30
+ Redcarpet::Render::HTML.new(render_options), extensions
29
31
  )
30
32
  end
31
-
32
- # ---------------------------------------------------------------------
33
-
34
- class << self
35
- attr_accessor :configuration
36
-
37
- def configure
38
- @configuration ||= Configuration.new
39
- yield @configuration
40
- end
41
-
42
- def configuration
43
- @configuration ||= Configuration.new
44
- end
45
- end
46
-
47
33
  end
48
-
49
- # ---------------------------------------------------------------------
50
-
51
34
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormMarkdownEditor
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,8 +2,8 @@ require "simple_form"
2
2
 
3
3
  require "simple_form_markdown_editor/configuration"
4
4
  require "simple_form_markdown_editor/engine"
5
+ require "simple_form_markdown_editor/markdown_editor_input"
5
6
  require "simple_form_markdown_editor/renderer"
6
- require "simple_form_markdown_editor/simple_form_markdown_editor"
7
7
  require "simple_form_markdown_editor/version"
8
8
 
9
9
  require "i18n"
@@ -18,4 +18,4 @@ end
18
18
 
19
19
  # ---------------------------------------------------------------------
20
20
 
21
- I18n.load_path += Dir.glob(File.join( File.dirname(__FILE__), 'config', 'locales', '*.yml' ))
21
+ I18n.load_path += Dir.glob(File.join( File.dirname(__FILE__), 'config', 'locales', '*.yml' ))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_markdown_editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Celizna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-05 00:00:00.000000000 Z
12
+ date: 2015-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -106,8 +106,8 @@ files:
106
106
  - lib/simple_form_markdown_editor.rb
107
107
  - lib/simple_form_markdown_editor/configuration.rb
108
108
  - lib/simple_form_markdown_editor/engine.rb
109
+ - lib/simple_form_markdown_editor/markdown_editor_input.rb
109
110
  - lib/simple_form_markdown_editor/renderer.rb
110
- - lib/simple_form_markdown_editor/simple_form_markdown_editor.rb
111
111
  - lib/simple_form_markdown_editor/version.rb
112
112
  - simple_form_markdown_editor.gemspec
113
113
  - test/dummy/.gitignore
@@ -164,16 +164,6 @@ files:
164
164
  - test/dummy/public/500.html
165
165
  - test/dummy/public/favicon.ico
166
166
  - test/dummy/public/robots.txt
167
- - test/dummy/test/controllers/.keep
168
- - test/dummy/test/controllers/editor_tests_controller_test.rb
169
- - test/dummy/test/fixtures/.keep
170
- - test/dummy/test/fixtures/editor_tests.yml
171
- - test/dummy/test/helpers/.keep
172
- - test/dummy/test/integration/.keep
173
- - test/dummy/test/mailers/.keep
174
- - test/dummy/test/models/.keep
175
- - test/dummy/test/models/editor_test_test.rb
176
- - test/dummy/test/test_helper.rb
177
167
  - test/dummy/vendor/assets/javascripts/.keep
178
168
  - test/dummy/vendor/assets/stylesheets/.keep
179
169
  homepage: https://github.com/tomasc/simple_form_markdown_editor
@@ -255,15 +245,5 @@ test_files:
255
245
  - test/dummy/public/500.html
256
246
  - test/dummy/public/favicon.ico
257
247
  - test/dummy/public/robots.txt
258
- - test/dummy/test/controllers/.keep
259
- - test/dummy/test/controllers/editor_tests_controller_test.rb
260
- - test/dummy/test/fixtures/.keep
261
- - test/dummy/test/fixtures/editor_tests.yml
262
- - test/dummy/test/helpers/.keep
263
- - test/dummy/test/integration/.keep
264
- - test/dummy/test/mailers/.keep
265
- - test/dummy/test/models/.keep
266
- - test/dummy/test/models/editor_test_test.rb
267
- - test/dummy/test/test_helper.rb
268
248
  - test/dummy/vendor/assets/javascripts/.keep
269
249
  - test/dummy/vendor/assets/stylesheets/.keep
File without changes
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class EditorTestsControllerTest < ActionController::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
File without changes
@@ -1,7 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
-
3
- one:
4
- markdown: MyString
5
-
6
- two:
7
- markdown: MyString
File without changes
File without changes
File without changes
File without changes
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class EditorTestTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,7 +0,0 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
4
-
5
- class ActiveSupport::TestCase
6
- # Add more helper methods to be used by all tests here...
7
- end