markdown-rails 2.0.0.alpha4 → 2.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df9409534d893fd18f8ea4312fae865d4d228387217d83976a108c1eca3bcb4a
4
- data.tar.gz: 943cae0bd4ef19becaa5e243d59982c073fd5a8a1f3f066a7da8ecb5d274cdc8
3
+ metadata.gz: f1f1b4ce5ea92d61301ed3e7d2750d9cc5db2054ca3b589f832acfde85424991
4
+ data.tar.gz: 5780eab553c1dce45dae009b8edcaf6cb5c346036c38ee7f3ff6617d8a730a2f
5
5
  SHA512:
6
- metadata.gz: 8c985143f8649306207650a0d3ae6eb4f0e317bbe1fb3592c94fc67b94f441d2b0ad08072ce0e45b32001f10e6164e9a04e54eafc1437a60d87ffc939d614cc2
7
- data.tar.gz: f71fb88d71fc8ca3ea0eb443934c57724d8584a502a9786ccd8e2cfdef1f98de4eaf24cc72fe07dacb55a7ea8a3f13a38464c44fe6bf2be4b473fcc812d573d2
6
+ metadata.gz: 61a346737cb1ed980d6ad9e3d4e0454d58bc47acd031ea9a594f2359c6764b3eb00c0516fb43699d666c902876d07039b16d4910736775c702e8160a78b6c7f0
7
+ data.tar.gz: 64b58bf2af05b1227ef08dc6e91b9b98568ec8c726ad2953708d573d70d8b6abf982db2baf8b52e998f863560922efe611f167db415c5c96eeb1e1dae4aabcc4
data/README.md CHANGED
@@ -26,7 +26,7 @@ $ bundle add 'markdown-rails'
26
26
  Then from the root of your Rails project, run:
27
27
 
28
28
  ```sh
29
- $ bin/rails g markdown:install
29
+ $ bin/rails g markdown_rails:install
30
30
  ```
31
31
 
32
32
  This adds a `config/initializers/markdown.rb` file where you can register template handler for your Markdown renders that are located in `./app/markdown/*.rb`.
@@ -44,7 +44,7 @@ gem "markdown-rails", "~> 2.0.0"
44
44
  Then from the root of your Rails project, run:
45
45
 
46
46
  ```sh
47
- $ bin/rails g markdown:install
47
+ $ bin/rails g markdown_rails:install
48
48
  ```
49
49
 
50
50
  If you have an existing file in `config/initializers/markdown.rb` you'll need to move those settings over. Note that 1.x used `RDiscount` as the default renderer, which was replaced by `Redcarpet` in 2.x.
@@ -58,11 +58,11 @@ Applications commonly need various markdown variants within one application. For
58
58
  # Restart the server to see changes made to this file.
59
59
 
60
60
  # Setup markdown stacks to work with different template handler in Rails.
61
- Markdown::Rails.handle :md do
61
+ MarkdownRails.handle :md do
62
62
  ApplicationMarkdown.new
63
63
  end
64
64
 
65
- Markdown::Rails.handle :crazymd do
65
+ MarkdownRails.handle :crazymd do
66
66
  MyCrazyMarkdown.new
67
67
  end
68
68
  ```
@@ -71,11 +71,11 @@ end
71
71
 
72
72
  Only enable Erb in Markdown if you trust the source of the file. Do not enable it for markdown provided by users or they will be able to execute arbitrary Ruby code.
73
73
 
74
- To enable Erb, you can tell Rails to render all view files ending with `.markerb` using the `Markdown::Rails::Handler::Erb` handler.
74
+ To enable Erb, you can tell Rails to render all view files ending with `.markerb` using the `MarkdownRails::Handler::Erb` handler.
75
75
 
76
76
  ```ruby
77
77
  # ./config/initializers/markdown.rb
78
- Markdown::Rails.handle :markerb, with: Markdown::Rails::Handler::Erb do
78
+ MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
79
79
  ApplicationMarkdown.new
80
80
  end
81
81
  ```
@@ -87,11 +87,11 @@ You *could* change `:markerb` to `:md`, but I don't recommend it for all Markdow
87
87
  # Restart the server to see changes made to this file.
88
88
 
89
89
  # Setup markdown stacks to work with different template handler in Rails.
90
- Markdown::Rails.handle :md do
90
+ MarkdownRails.handle :md do
91
91
  ApplicationMarkdown.new
92
92
  end
93
93
 
94
- Markdown::Rails.handle :markerb, with: Markdown::Rails::Handler::Erb do
94
+ MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
95
95
  ApplicationMarkdown.new
96
96
  end
97
97
  ```
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Installs MarkdownRails to your Rails project
3
+
4
+ Example:
5
+ bin/rails generate markdown_rails:install
6
+
7
+ This will create:
8
+ config/initializers/markdown.rb
9
+ app/markdown/application_markdown.rb
@@ -1,4 +1,4 @@
1
- class Markdown::InstallGenerator < Rails::Generators::Base
1
+ class MarkdownRails::InstallGenerator < Rails::Generators::Base
2
2
  source_root File.expand_path("templates", __dir__)
3
3
 
4
4
  def copy_files
@@ -1,13 +1,13 @@
1
1
  # You should read the docs at https://github.com/vmg/redcarpet and probably
2
2
  # delete a bunch of stuff below if you don't need it.
3
3
 
4
- class ApplicationMarkdown < Markdown::Rails::Renderer::Rails
4
+ class ApplicationMarkdown < MarkdownRails::Renderer::Rails
5
5
  # Reformats your boring punctation like " and " into “ and ” so you can look
6
6
  # and feel smarter. Read the docs at https://github.com/vmg/redcarpet#also-now-our-pants-are-much-smarter
7
7
  include Redcarpet::Render::SmartyPants
8
8
 
9
9
  # If you need access to ActionController::Base.helpers, you can delegate by uncommenting
10
- # and adding to the list below. Several are already included for you in the `Markdown::Rails::Renderer::Rails`,
10
+ # and adding to the list below. Several are already included for you in the `MarkdownRails::Renderer::Rails`,
11
11
  # but you can add more here.
12
12
  #
13
13
  # To see a list of methods available run `bin/rails runner "puts ActionController::Base.helpers.public_methods.sort"`
@@ -1,13 +1,13 @@
1
1
  # Restart the server to see changes made to this file.
2
2
 
3
3
  # Setup markdown stacks to work with different template handler in Rails.
4
- Markdown::Rails.handle :md, :markdown do
4
+ MarkdownRails.handle :md, :markdown do
5
5
  ApplicationMarkdown.new
6
6
  end
7
7
 
8
8
  # Don't use Erb for untrusted markdown content created by users; otherwise they
9
9
  # can execute arbitrary code on your server. This should only be used for input you
10
10
  # trust, like content files from your code repo.
11
- Markdown::Rails.handle :markerb, with: Markdown::Rails::Handler::Erb do
11
+ MarkdownRails.handle :markerb, with: MarkdownRails::Handler::Erb do
12
12
  ApplicationMarkdown.new
13
13
  end
@@ -0,0 +1,4 @@
1
+ module MarkdownRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module MarkdownRails
2
+ module Handler
3
+ class Erb < Markdown
4
+ def call(template, source = template.source)
5
+ compiled_source = compile_erb template, source
6
+ # TODO: This won't properly handle initializer blocks. Somehow
7
+ # I need to pass a reference to the block that's passed in.
8
+ "#{markdown.class.name}.new.renderer.render(begin;#{compiled_source};end).html_safe"
9
+ end
10
+
11
+ private
12
+
13
+ def compile_erb(template, source)
14
+ erb.call(template, source)
15
+ end
16
+
17
+ def erb
18
+ ActionView::Template.registered_template_handler(:erb)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ module MarkdownRails
2
+ module Handler
3
+ # We cannot use MarkdownRails because it conflicts with RDiscount's Markdown class
4
+ class Markdown
5
+ def initialize(&block)
6
+ @markdown = block
7
+ end
8
+
9
+ def call(template, source = template.source)
10
+ renderer.render(source).inspect + '.html_safe'
11
+ end
12
+
13
+ def self.handle(*extensions, &block)
14
+ Array(extensions).each do |extension|
15
+ handler = new &block
16
+ ActionView::Template.register_template_handler extension, handler
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def markdown
23
+ @cache = nil unless cache_enabled?
24
+ @cache ||= @markdown.call
25
+ end
26
+
27
+ def renderer
28
+ @renderer = nil unless cache_enabled?
29
+ @renderer ||= markdown.renderer
30
+ end
31
+
32
+ def cache_enabled?
33
+ ::Rails.configuration.cache_classes
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module MarkdownRails
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,26 @@
1
+ module MarkdownRails
2
+ module Renderer
3
+ class Base < Redcarpet::Render::HTML
4
+ def enable
5
+ # This is a very restrictive Markdown renderer that errs on the side of safety.
6
+ # For more details read the docs at https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderer-for-lunch
7
+ [
8
+ :filter_html,
9
+ :no_images,
10
+ :no_links,
11
+ :no_styles,
12
+ :safe_links_only
13
+ ]
14
+ end
15
+
16
+ def renderer
17
+ ::Redcarpet::Markdown.new(self.class, **features)
18
+ end
19
+
20
+ private
21
+ def features
22
+ Hash[Array(enable).map{ |feature| [ feature, true ] }]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module MarkdownRails
2
+ module Renderer
3
+ class Rails < Base
4
+ include ::Rails.application.routes.url_helpers
5
+
6
+ delegate \
7
+ :asset_digest_path,
8
+ :asset_path,
9
+ :asset_url,
10
+ :audio_path,
11
+ :audio_tag,
12
+ :audio_url,
13
+ :font_path,
14
+ :font_url,
15
+ :image_path,
16
+ :image_tag,
17
+ :image_url,
18
+ :video_path,
19
+ :video_tag,
20
+ :video_url,
21
+ :tag,
22
+ :content_tag,
23
+ :render,
24
+ :request,
25
+ :turbo_frame_tag,
26
+ :controller,
27
+ :raw,
28
+ to: :helpers
29
+
30
+ def image(link, title, alt)
31
+ image_tag link, title: title, alt: alt
32
+ end
33
+
34
+ protected
35
+ def helpers
36
+ ::ActionController::Base.helpers
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module MarkdownRails
2
+ VERSION = "2.0.0.alpha5"
3
+ end
@@ -1 +1,18 @@
1
- require "markdown/rails"
1
+ require "markdown-rails/version"
2
+ require "markdown-rails/engine"
3
+
4
+ module MarkdownRails
5
+ def self.handle(*extensions, with: Handler::Markdown, &block)
6
+ with.handle *extensions, &block
7
+ end
8
+
9
+ module Handler
10
+ autoload :Markdown, "markdown-rails/handler/markdown"
11
+ autoload :Erb, "markdown-rails/handler/erb"
12
+ end
13
+
14
+ module Renderer
15
+ autoload :Base, "markdown-rails/renderer/base"
16
+ autoload :Rails, "markdown-rails/renderer/rails"
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha4
4
+ version: 2.0.0.alpha5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
@@ -50,19 +50,18 @@ files:
50
50
  - README.md
51
51
  - Rakefile
52
52
  - app/assets/config/markdown_rails_manifest.js
53
- - lib/generators/markdown/install/USAGE
54
- - lib/generators/markdown/install/install_generator.rb
55
- - lib/generators/markdown/install/templates/app/markdown/application_markdown.rb
56
- - lib/generators/markdown/install/templates/config/initializers/markdown.rb
53
+ - lib/generators/markdown-rails/install/USAGE
54
+ - lib/generators/markdown-rails/install/install_generator.rb
55
+ - lib/generators/markdown-rails/install/templates/app/markdown/application_markdown.rb
56
+ - lib/generators/markdown-rails/install/templates/config/initializers/markdown.rb
57
57
  - lib/markdown-rails.rb
58
- - lib/markdown/rails.rb
59
- - lib/markdown/rails/engine.rb
60
- - lib/markdown/rails/handler/erb.rb
61
- - lib/markdown/rails/handler/markdown.rb
62
- - lib/markdown/rails/railtie.rb
63
- - lib/markdown/rails/renderer/base.rb
64
- - lib/markdown/rails/renderer/rails.rb
65
- - lib/markdown/rails/version.rb
58
+ - lib/markdown-rails/engine.rb
59
+ - lib/markdown-rails/handler/erb.rb
60
+ - lib/markdown-rails/handler/markdown.rb
61
+ - lib/markdown-rails/railtie.rb
62
+ - lib/markdown-rails/renderer/base.rb
63
+ - lib/markdown-rails/renderer/rails.rb
64
+ - lib/markdown-rails/version.rb
66
65
  - lib/tasks/markdown/rails_tasks.rake
67
66
  homepage: https://github.com/sitepress/markdown-rails
68
67
  licenses:
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- bin/rails generate install Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,6 +0,0 @@
1
- module Markdown
2
- module Rails
3
- class Engine < ::Rails::Engine
4
- end
5
- end
6
- end
@@ -1,24 +0,0 @@
1
- module Markdown
2
- module Rails
3
- module Handler
4
- class Erb < Markdown
5
- def call(template, source = template.source)
6
- compiled_source = compile_erb template, source
7
- # TODO: This won't properly handle initializer blocks. Somehow
8
- # I need to pass a reference to the block that's passed in.
9
- "#{markdown.class.name}.new.renderer.render(begin;#{compiled_source};end).html_safe"
10
- end
11
-
12
- private
13
-
14
- def compile_erb(template, source)
15
- erb.call(template, source)
16
- end
17
-
18
- def erb
19
- ActionView::Template.registered_template_handler(:erb)
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,39 +0,0 @@
1
- module Markdown
2
- module Rails
3
- module Handler
4
- # We cannot use Markdown::Rails because it conflicts with RDiscount's Markdown class
5
- class Markdown
6
- def initialize(&block)
7
- @markdown = block
8
- end
9
-
10
- def call(template, source = template.source)
11
- renderer.render(source).inspect + '.html_safe'
12
- end
13
-
14
- def self.handle(*extensions, &block)
15
- Array(extensions).each do |extension|
16
- handler = new &block
17
- ActionView::Template.register_template_handler extension, handler
18
- end
19
- end
20
-
21
- private
22
-
23
- def markdown
24
- @cache = nil unless cache_enabled?
25
- @cache ||= @markdown.call
26
- end
27
-
28
- def renderer
29
- @renderer = nil unless cache_enabled?
30
- @renderer ||= markdown.renderer
31
- end
32
-
33
- def cache_enabled?
34
- ::Rails.configuration.cache_classes
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,6 +0,0 @@
1
- module Markdown
2
- module Rails
3
- class Railtie < ::Rails::Railtie
4
- end
5
- end
6
- end
@@ -1,28 +0,0 @@
1
- module Markdown
2
- module Rails
3
- module Renderer
4
- class Base < Redcarpet::Render::HTML
5
- def enable
6
- # This is a very restrictive Markdown renderer that errs on the side of safety.
7
- # For more details read the docs at https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderer-for-lunch
8
- [
9
- :filter_html,
10
- :no_images,
11
- :no_links,
12
- :no_styles,
13
- :safe_links_only
14
- ]
15
- end
16
-
17
- def renderer
18
- ::Redcarpet::Markdown.new(self.class, **features)
19
- end
20
-
21
- private
22
- def features
23
- Hash[Array(enable).map{ |feature| [ feature, true ] }]
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,42 +0,0 @@
1
- module Markdown
2
- module Rails
3
- module Renderer
4
- class Rails < Base
5
- include ::Rails.application.routes.url_helpers
6
-
7
- delegate \
8
- :asset_digest_path,
9
- :asset_path,
10
- :asset_url,
11
- :audio_path,
12
- :audio_tag,
13
- :audio_url,
14
- :font_path,
15
- :font_url,
16
- :image_path,
17
- :image_tag,
18
- :image_url,
19
- :video_path,
20
- :video_tag,
21
- :video_url,
22
- :tag,
23
- :content_tag,
24
- :render,
25
- :request,
26
- :turbo_frame_tag,
27
- :controller,
28
- :raw,
29
- to: :helpers
30
-
31
- def image(link, title, alt)
32
- image_tag link, title: title, alt: alt
33
- end
34
-
35
- protected
36
- def helpers
37
- ::ActionController::Base.helpers
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,5 +0,0 @@
1
- module Markdown
2
- module Rails
3
- VERSION = "2.0.0.alpha4"
4
- end
5
- end
@@ -1,20 +0,0 @@
1
- require "markdown/rails/version"
2
- require "markdown/rails/engine"
3
-
4
- module Markdown
5
- module Rails
6
- def self.handle(*extensions, with: Handler::Markdown, &block)
7
- with.handle *extensions, &block
8
- end
9
-
10
- module Handler
11
- autoload :Markdown, "markdown/rails/handler/markdown"
12
- autoload :Erb, "markdown/rails/handler/erb"
13
- end
14
-
15
- module Renderer
16
- autoload :Base, "markdown/rails/renderer/base"
17
- autoload :Rails, "markdown/rails/renderer/rails"
18
- end
19
- end
20
- end