markerb 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +17 -1
- data/lib/generators/markerb/mailer/templates/layout.markerb +1 -0
- data/lib/markerb.rb +2 -6
- data/lib/markerb/markdown.rb +17 -0
- data/lib/markerb/version.rb +1 -1
- data/test/markdown_test.rb +30 -0
- data/test/test_helper.rb +4 -0
- metadata +22 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd7b5190ebf252b9548185f66b1652ef1660e23
|
4
|
+
data.tar.gz: 5294a6472a029bbcf3494892dc8e2ff44ee8ead1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba587a666a3394d8ce656c9685ec12dba5eb7d791956ad4bc50ad0264746e2150e44689f5fcf4fe0e897a520df8839a630b52ec9870122fa684a7a696861e43d
|
7
|
+
data.tar.gz: 54d187b157c8df8fb3f19876e948c834264a65285556ef506c7057a91325c53c7dc3764bcefbfaa7cb1a99f87cc13e6dfff101f103638787cbc04055664e5fce
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright 2011-
|
1
|
+
Copyright 2011-2015 Plataformatec (http://blog.plataformatec.com.br)
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -34,6 +34,22 @@ It will generate two parts, one in text and another in html when delivered. Befo
|
|
34
34
|
|
35
35
|
Enjoy!
|
36
36
|
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
Add it to your Gemfile, with either the `redcarpet` or `kramdown` parser:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
gem 'markerb'
|
43
|
+
gem 'redcarpet', '>= 2.0'
|
44
|
+
# gem 'kramdown'
|
45
|
+
```
|
46
|
+
|
47
|
+
Run the following command to install it:
|
48
|
+
|
49
|
+
```console
|
50
|
+
bundle install
|
51
|
+
```
|
52
|
+
|
37
53
|
## Bug reports
|
38
54
|
|
39
55
|
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
|
@@ -48,4 +64,4 @@ https://github.com/plataformatec/markerb/issues
|
|
48
64
|
|
49
65
|
## License
|
50
66
|
|
51
|
-
MIT License. Copyright 2011-
|
67
|
+
MIT License. Copyright 2011-2015 Plataformatec. http://plataformatec.com.br
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= yield %>
|
data/lib/markerb.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
require "action_view"
|
2
2
|
require "action_view/template"
|
3
|
-
require "
|
3
|
+
require "markerb/markdown"
|
4
4
|
require "markerb/railtie"
|
5
5
|
|
6
6
|
module Markerb
|
7
|
-
mattr_accessor :processing_options, :renderer
|
8
|
-
@@processing_options = {}
|
9
|
-
@@renderer = Redcarpet::Render::HTML
|
10
|
-
|
11
7
|
class Handler
|
12
8
|
def erb_handler
|
13
9
|
@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
|
@@ -16,7 +12,7 @@ module Markerb
|
|
16
12
|
def call(template)
|
17
13
|
compiled_source = erb_handler.call(template)
|
18
14
|
if template.formats.include?(:html)
|
19
|
-
"
|
15
|
+
"Markerb::Markdown.to_html(begin;#{compiled_source};end).html_safe"
|
20
16
|
else
|
21
17
|
compiled_source
|
22
18
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Markerb
|
2
|
+
mattr_accessor :processing_options, :renderer
|
3
|
+
@@processing_options = {}
|
4
|
+
|
5
|
+
class Markdown
|
6
|
+
def self.to_html(compiled_source)
|
7
|
+
if defined?(Redcarpet)
|
8
|
+
Markerb.renderer ||= Redcarpet::Render::HTML
|
9
|
+
Redcarpet::Markdown.new(Markerb.renderer, Markerb.processing_options).render(compiled_source)
|
10
|
+
elsif defined?(Kramdown)
|
11
|
+
Kramdown::Document.new(compiled_source, Markerb.processing_options).to_html
|
12
|
+
else
|
13
|
+
raise StandardError, "Markdown processor unavailable, please add either Redcarpet or Kramdown to your project"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/markerb/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class MarkdownTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@original_redcarpet = Redcarpet
|
6
|
+
@original_kramdown = Kramdown
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
Object.const_set(:Redcarpet, @original_redcarpet) unless defined?(Redcarpet)
|
11
|
+
Object.const_set(:Kramdown, @original_kramdown) unless defined?(Kramdown)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'with Redcarpet markdown processor' do
|
15
|
+
Object.send(:remove_const, :Kramdown)
|
16
|
+
assert_equal "<p>Dual templates <strong>rocks</strong>!</p>", Markerb::Markdown.to_html("Dual templates **rocks**!").strip
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'with Kramdown markdown processor' do
|
20
|
+
Object.send(:remove_const, :Redcarpet)
|
21
|
+
assert_equal "<p>Dual templates <strong>rocks</strong>!</p>", Markerb::Markdown.to_html("Dual templates **rocks**!").strip
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'when there is no known markdown processor available' do
|
25
|
+
Object.send(:remove_const, :Redcarpet)
|
26
|
+
Object.send(:remove_const, :Kramdown)
|
27
|
+
|
28
|
+
assert_raise(StandardError) { Markerb::Markdown.to_html("Dual templates **rocks**!") }
|
29
|
+
end
|
30
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -9,10 +9,14 @@ require "action_mailer"
|
|
9
9
|
require "rails/railtie"
|
10
10
|
require "rails/generators"
|
11
11
|
require "rails/generators/test_case"
|
12
|
+
require "redcarpet"
|
13
|
+
require "kramdown"
|
12
14
|
|
13
15
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
14
16
|
require "markerb"
|
15
17
|
|
18
|
+
ActiveSupport::TestCase.test_order = :sorted if ActiveSupport::TestCase.respond_to? :test_order=
|
19
|
+
|
16
20
|
# Avoid annoying warning from I18n.
|
17
21
|
I18n.enforce_available_locales = false
|
18
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markerb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -17,13 +17,27 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: kramdown
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Multipart templates made easy with Markdown + ERb
|
28
42
|
email: contact@plataformatec.com.br
|
29
43
|
executables: []
|
@@ -33,11 +47,14 @@ files:
|
|
33
47
|
- MIT-LICENSE
|
34
48
|
- README.md
|
35
49
|
- lib/generators/markerb/mailer/mailer_generator.rb
|
50
|
+
- lib/generators/markerb/mailer/templates/layout.markerb
|
36
51
|
- lib/generators/markerb/mailer/templates/view.markerb
|
37
52
|
- lib/markerb.rb
|
53
|
+
- lib/markerb/markdown.rb
|
38
54
|
- lib/markerb/railtie.rb
|
39
55
|
- lib/markerb/version.rb
|
40
56
|
- test/generator_test.rb
|
57
|
+
- test/markdown_test.rb
|
41
58
|
- test/markerb_test.rb
|
42
59
|
- test/test_helper.rb
|
43
60
|
homepage: http://github.com/plataformatec/markerb
|
@@ -60,11 +77,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
77
|
version: '0'
|
61
78
|
requirements: []
|
62
79
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.4.8
|
64
81
|
signing_key:
|
65
82
|
specification_version: 4
|
66
83
|
summary: Multipart templates made easy with Markdown + ERb
|
67
84
|
test_files:
|
68
85
|
- test/generator_test.rb
|
86
|
+
- test/markdown_test.rb
|
69
87
|
- test/markerb_test.rb
|
70
88
|
- test/test_helper.rb
|