shortcode 1.2.1 → 2.0.0.pre
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 +4 -4
- data/.rubocop +1 -0
- data/.rubocop.yml +72 -0
- data/.travis.yml +7 -6
- data/Appraisals +3 -7
- data/Gemfile +2 -2
- data/Gemfile.lock +136 -18
- data/bin/appraisal +17 -0
- data/bin/rspec +17 -0
- data/bin/rubocop +17 -0
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/gemfiles/rails_5.0.gemfile +1 -1
- data/gemfiles/rails_5.1.gemfile +1 -1
- data/lib/shortcode.rb +17 -41
- data/lib/shortcode/configuration.rb +3 -1
- data/lib/shortcode/parser.rb +21 -17
- data/lib/shortcode/presenter.rb +18 -15
- data/lib/shortcode/processor.rb +3 -1
- data/lib/shortcode/railtie.rb +2 -0
- data/lib/shortcode/tag.rb +11 -4
- data/lib/shortcode/template_binding.rb +12 -7
- data/lib/shortcode/transformer.rb +8 -4
- data/lib/shortcode/version.rb +3 -1
- data/shortcode.gemspec +10 -7
- data/spec/.rubocop.yml +17 -0
- data/spec/performance_spec.rb +4 -5
- data/spec/rails_helpers_spec.rb +25 -31
- data/spec/shortcode/parser_spec.rb +313 -0
- data/spec/shortcode/presenter_spec.rb +118 -0
- data/spec/shortcode/tag_spec.rb +73 -0
- data/spec/shortcode_spec.rb +40 -37
- data/spec/spec_helper.rb +6 -20
- data/spec/support/fixtures.rb +4 -6
- data/spec/support/presenters/missing_attributes_presenter.rb +3 -6
- data/spec/support/presenters/missing_content_presenter.rb +3 -6
- data/spec/support/presenters/missing_for_presenter.rb +3 -6
- data/spec/support/presenters/missing_initialize_presenter.rb +3 -6
- data/spec/support/presenters/multiple_presenter.rb +4 -5
- data/spec/support/presenters/my_presenter.rb +3 -4
- data/spec/support/presenters/other_presenter.rb +3 -4
- data/spec/template_parsers_spec.rb +21 -22
- data/spec/transformer_spec.rb +26 -36
- metadata +75 -24
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/spec/parser_spec.rb +0 -307
- data/spec/presenter_spec.rb +0 -126
- data/spec/tag_spec.rb +0 -86
data/spec/shortcode_spec.rb
CHANGED
@@ -1,82 +1,85 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "parslet/rig/rspec"
|
3
|
+
require "pp"
|
4
4
|
|
5
5
|
describe Shortcode do
|
6
|
-
|
7
6
|
let(:simple_quote) { load_fixture :simple_quote }
|
8
7
|
let(:simple_quote_output) { load_fixture :simple_quote_output, :html }
|
9
8
|
|
9
|
+
let(:shortcode) { described_class.new }
|
10
|
+
let(:configuration) { shortcode.configuration }
|
11
|
+
|
12
|
+
before do
|
13
|
+
configuration.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
14
|
+
end
|
15
|
+
|
10
16
|
context "simple_quote" do
|
17
|
+
before do
|
18
|
+
configuration.block_tags = [:quote]
|
19
|
+
end
|
11
20
|
|
12
21
|
it "converts into html" do
|
13
|
-
expect(
|
22
|
+
expect(shortcode.process(simple_quote).delete("\n")).to eq(simple_quote_output)
|
14
23
|
end
|
15
|
-
|
16
24
|
end
|
17
25
|
|
18
26
|
context "erb templates" do
|
27
|
+
before do
|
28
|
+
configuration.block_tags = [:quote]
|
29
|
+
end
|
19
30
|
|
20
31
|
it "converts into html" do
|
21
|
-
expect(
|
32
|
+
expect(shortcode.process(simple_quote).delete("\n")).to eq(simple_quote_output)
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
25
36
|
context "configuration" do
|
26
|
-
|
27
37
|
describe "block_tags" do
|
28
|
-
|
29
38
|
before do
|
30
|
-
|
31
|
-
config.block_tags = []
|
32
|
-
end
|
39
|
+
configuration.block_tags = []
|
33
40
|
end
|
34
41
|
|
35
42
|
it "handles an empty array" do
|
36
|
-
expect {
|
43
|
+
expect { shortcode.process(simple_quote) }.not_to raise_error
|
37
44
|
end
|
38
|
-
|
39
45
|
end
|
40
46
|
|
41
47
|
describe "self_closing_tags" do
|
42
|
-
|
43
48
|
before do
|
44
|
-
|
45
|
-
config.self_closing_tags = []
|
46
|
-
end
|
49
|
+
configuration.self_closing_tags = []
|
47
50
|
end
|
48
51
|
|
49
52
|
it "handles an empty array" do
|
50
|
-
expect {
|
53
|
+
expect { shortcode.process(simple_quote) }.not_to raise_error
|
51
54
|
end
|
52
|
-
|
53
55
|
end
|
54
|
-
|
55
56
|
end
|
56
57
|
|
57
58
|
context "multiple instances" do
|
58
|
-
let(:shortcode1) { Shortcode.new }
|
59
|
-
let(:shortcode2) { Shortcode.new }
|
60
|
-
|
61
59
|
it "allows having multiple Shortcode instances that have independent configurations" do
|
62
|
-
expect(
|
60
|
+
expect(described_class.new.configuration).not_to be(described_class.new.configuration)
|
63
61
|
end
|
64
62
|
|
65
|
-
|
66
|
-
shortcode1.
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
context "configuration" do
|
64
|
+
let(:shortcode1) { described_class.new }
|
65
|
+
let(:shortcode2) { described_class.new }
|
66
|
+
|
67
|
+
before do
|
68
|
+
shortcode1.setup do |config|
|
69
|
+
config.self_closing_tags << :quote
|
70
|
+
config.templates = { quote: "i am from shortcode 1" }
|
71
|
+
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
shortcode2.setup do |config|
|
74
|
+
config.self_closing_tags << :quote
|
75
|
+
config.templates = { quote: "i am from shortcode 2" }
|
76
|
+
end
|
74
77
|
end
|
75
78
|
|
76
|
-
|
77
|
-
|
79
|
+
it "uses the shortcode instance's configuration to process shortcodes" do
|
80
|
+
expect(shortcode1.process("[quote]")).to eq("i am from shortcode 1")
|
81
|
+
expect(shortcode2.process("[quote]")).to eq("i am from shortcode 2")
|
82
|
+
end
|
78
83
|
end
|
79
|
-
|
80
84
|
end
|
81
|
-
|
82
85
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
2
|
|
3
3
|
if ENV["CI"]
|
4
|
-
require
|
4
|
+
require "coveralls"
|
5
5
|
Coveralls.wear!
|
6
6
|
end
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
8
|
+
require "rspec"
|
9
|
+
require "rails"
|
10
|
+
require "action_view"
|
11
|
+
require "shortcode"
|
12
|
+
require "support/fixtures"
|
13
13
|
|
14
14
|
# Set slim's attribute quotes to use single quotes so it's the same as haml
|
15
15
|
Slim::Engine.set_options attr_quote: "'"
|
@@ -17,18 +17,4 @@ Slim::Engine.set_options attr_quote: "'"
|
|
17
17
|
RSpec.configure do |config|
|
18
18
|
config.order = "random"
|
19
19
|
config.color = true
|
20
|
-
|
21
|
-
config.before(:each) do
|
22
|
-
Shortcode.setup do |config|
|
23
|
-
config.template_parser = :erb
|
24
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
25
|
-
config.templates = {}
|
26
|
-
config.check_config_templates_first = true
|
27
|
-
config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper, :custom_helper]
|
28
|
-
config.self_closing_tags = [:timeline_event, :timeline_info]
|
29
|
-
config.attribute_quote_type = '"'
|
30
|
-
config.use_attribute_quotes = true
|
31
|
-
config.presenters = {}
|
32
|
-
end
|
33
|
-
end
|
34
20
|
end
|
data/spec/support/fixtures.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
RSpec.configure do |
|
2
|
-
|
3
|
-
def load_fixture(name, type='txt')
|
1
|
+
RSpec.configure do |_config|
|
2
|
+
def load_fixture(name, type="txt")
|
4
3
|
type = type.to_s
|
5
|
-
string = File.read(File.join(File.dirname(__FILE__),
|
6
|
-
type ==
|
4
|
+
string = File.read(File.join(File.dirname(__FILE__), "fixtures", "#{name}.#{type}"))
|
5
|
+
type == "txt" ? string : string.delete("\n")
|
7
6
|
end
|
8
|
-
|
9
7
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
class MultiplePresenter
|
2
2
|
|
3
3
|
def self.for
|
4
|
-
[
|
4
|
+
%i[quote item]
|
5
5
|
end
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(_attributes, content, additional_attributes)
|
8
8
|
@content = content
|
9
9
|
@additional_attributes = additional_attributes
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
@content
|
14
|
-
end
|
12
|
+
attr_reader :content
|
15
13
|
|
16
14
|
def attributes
|
17
15
|
@additional_attributes || { title: "my custom title" }
|
18
16
|
end
|
17
|
+
|
19
18
|
end
|
@@ -4,16 +4,15 @@ class MyPresenter
|
|
4
4
|
:quote
|
5
5
|
end
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(_attributes, content, additional_attributes)
|
8
8
|
@content = content
|
9
9
|
@additional_attributes = additional_attributes
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
@content
|
14
|
-
end
|
12
|
+
attr_reader :content
|
15
13
|
|
16
14
|
def attributes
|
17
15
|
@additional_attributes || { title: "my custom title" }
|
18
16
|
end
|
17
|
+
|
19
18
|
end
|
@@ -4,16 +4,15 @@ class OtherPresenter
|
|
4
4
|
:other
|
5
5
|
end
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(_attributes, content, additional_attributes)
|
8
8
|
@content = content
|
9
9
|
@additional_attributes = additional_attributes
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
@content
|
14
|
-
end
|
12
|
+
attr_reader :content
|
15
13
|
|
16
14
|
def attributes
|
17
15
|
@additional_attributes || { title: "my custom title" }
|
18
16
|
end
|
17
|
+
|
19
18
|
end
|
@@ -1,46 +1,45 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
describe "template parsers" do
|
1
|
+
require "spec_helper"
|
4
2
|
|
3
|
+
describe "template parsers", type: :feature do
|
5
4
|
let(:simple_quote) { load_fixture :simple_quote }
|
6
5
|
let(:simple_quote_output) { load_fixture :simple_quote_output, :html }
|
7
6
|
|
7
|
+
let(:shortcode) { Shortcode.new }
|
8
|
+
let(:configuration) { shortcode.configuration }
|
9
|
+
|
8
10
|
context "erb" do
|
11
|
+
before do
|
12
|
+
configuration.block_tags = [:quote]
|
13
|
+
configuration.template_parser = :erb
|
14
|
+
configuration.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
15
|
+
end
|
9
16
|
|
10
17
|
it "can render a template" do
|
11
|
-
expect(
|
18
|
+
expect(shortcode.process(simple_quote).delete("\n")).to eq(simple_quote_output)
|
12
19
|
end
|
13
|
-
|
14
20
|
end
|
15
21
|
|
16
22
|
context "haml" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
22
|
-
end
|
23
|
+
before do
|
24
|
+
configuration.block_tags = [:quote]
|
25
|
+
configuration.template_parser = :haml
|
26
|
+
configuration.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
23
27
|
end
|
24
28
|
|
25
29
|
it "can render a template" do
|
26
|
-
expect(
|
30
|
+
expect(shortcode.process(simple_quote).delete("\n").gsub("> <", "><")).to eq(simple_quote_output)
|
27
31
|
end
|
28
|
-
|
29
32
|
end
|
30
33
|
|
31
34
|
context "slim" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/slim"
|
37
|
-
end
|
35
|
+
before do
|
36
|
+
configuration.block_tags = [:quote]
|
37
|
+
configuration.template_parser = :slim
|
38
|
+
configuration.template_path = File.join File.dirname(__FILE__), "support/templates/slim"
|
38
39
|
end
|
39
40
|
|
40
41
|
it "can render a template" do
|
41
|
-
expect(
|
42
|
+
expect(shortcode.process(simple_quote).delete("\n")).to eq(simple_quote_output)
|
42
43
|
end
|
43
|
-
|
44
44
|
end
|
45
|
-
|
46
45
|
end
|
data/spec/transformer_spec.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "parslet/rig/rspec"
|
3
|
+
require "pp"
|
4
4
|
|
5
5
|
describe Shortcode do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:configuration) {
|
7
|
+
described_class.new.tap { |s|
|
8
|
+
s.setup do |config|
|
9
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
10
|
+
config.block_tags = %i[quote collapsible_list item timeline_person rails_helper]
|
11
|
+
config.self_closing_tags = %i[timeline_event timeline_info]
|
12
|
+
end
|
13
|
+
}.configuration
|
14
|
+
}
|
15
|
+
let(:parser) { Shortcode::Parser.new(configuration) }
|
16
|
+
let(:transformer) { Shortcode::Transformer.new(configuration) }
|
9
17
|
|
10
18
|
let(:simple_quote) { load_fixture :simple_quote }
|
11
19
|
let(:full_quote) { load_fixture :full_quote }
|
@@ -32,91 +40,73 @@ describe Shortcode do
|
|
32
40
|
let(:block_with_whitespace_output) { load_fixture :block_with_whitespace_output, :html }
|
33
41
|
|
34
42
|
context "simple_quote" do
|
35
|
-
|
36
43
|
it "converts into html" do
|
37
44
|
obj = parser.parse(simple_quote)
|
38
45
|
html = transformer.apply obj, additional_attributes: nil
|
39
|
-
expect(html.
|
46
|
+
expect(html.delete("\n")).to eq(simple_quote_output)
|
40
47
|
end
|
41
|
-
|
42
48
|
end
|
43
49
|
|
44
50
|
context "full_quote" do
|
45
|
-
|
46
51
|
it "converts into html" do
|
47
52
|
html = transformer.apply(parser.parse(full_quote), additional_attributes: nil)
|
48
|
-
expect(html.
|
53
|
+
expect(html.delete("\n")).to eq(full_quote_output)
|
49
54
|
end
|
50
|
-
|
51
55
|
end
|
52
56
|
|
53
57
|
context "quote_with_extras" do
|
54
|
-
|
55
58
|
it "converts into html" do
|
56
59
|
html = transformer.apply(parser.parse(quote_with_extras), additional_attributes: nil)
|
57
|
-
expect(html.
|
60
|
+
expect(html.delete("\n")).to eq(quote_with_extras_output)
|
58
61
|
end
|
59
|
-
|
60
62
|
end
|
61
63
|
|
62
64
|
context "simple_list" do
|
63
|
-
|
64
65
|
it "converts into html" do
|
65
66
|
html = transformer.apply(parser.parse(simple_list), additional_attributes: nil)
|
66
|
-
expect(html.
|
67
|
+
expect(html.delete("\n")).to eq(simple_list_output)
|
67
68
|
end
|
68
|
-
|
69
69
|
end
|
70
70
|
|
71
71
|
context "timeline_event" do
|
72
|
-
|
73
72
|
it "converts into html" do
|
74
73
|
html = transformer.apply(parser.parse(timeline_event), additional_attributes: nil)
|
75
|
-
expect(html.
|
74
|
+
expect(html.delete("\n")).to eq(timeline_event_output)
|
76
75
|
end
|
77
|
-
|
78
76
|
end
|
79
77
|
|
80
78
|
context "timeline_info" do
|
81
|
-
|
82
79
|
it "converts into html" do
|
83
80
|
html = transformer.apply(parser.parse(timeline_info), additional_attributes: nil)
|
84
|
-
expect(html.
|
81
|
+
expect(html.delete("\n")).to eq(timeline_info_output)
|
85
82
|
end
|
86
|
-
|
87
83
|
end
|
88
84
|
|
89
85
|
context "timeline_person" do
|
90
|
-
|
91
86
|
it "converts into html" do
|
92
87
|
html = transformer.apply(parser.parse(timeline_person), additional_attributes: nil)
|
93
|
-
expect(html.
|
88
|
+
expect(html.delete("\n")).to eq(timeline_person_output)
|
94
89
|
end
|
95
|
-
|
96
90
|
end
|
97
91
|
|
98
92
|
context "complex_snippet" do
|
99
|
-
|
100
93
|
it "converts into html" do
|
101
94
|
html = transformer.apply(parser.parse(complex_snippet), additional_attributes: nil)
|
102
|
-
expect(html.
|
95
|
+
expect(html.delete("\n")).to eq(complex_snippet_output)
|
103
96
|
end
|
104
97
|
end
|
105
98
|
|
106
99
|
context "erb templates" do
|
107
|
-
|
108
100
|
it "converts into html" do
|
109
101
|
html = transformer.apply(parser.parse(simple_quote), additional_attributes: nil)
|
110
|
-
expect(html.
|
102
|
+
expect(html.delete("\n")).to eq(simple_quote_output)
|
111
103
|
end
|
112
104
|
end
|
113
105
|
|
114
|
-
context
|
115
|
-
|
116
|
-
it 'is preserved after a block tag' do
|
106
|
+
context "whitespace" do
|
107
|
+
it "is preserved after a block tag" do
|
117
108
|
html = transformer.apply(parser.parse(block_with_whitespace), additional_attributes: nil)
|
118
|
-
expect(html.
|
109
|
+
expect(html.delete("\n")).to eq(block_with_whitespace_output)
|
119
110
|
end
|
120
|
-
|
121
111
|
end
|
122
112
|
end
|