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/presenter_spec.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'parslet/rig/rspec'
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
require 'support/presenters/my_presenter'
|
6
|
-
require 'support/presenters/other_presenter'
|
7
|
-
require 'support/presenters/multiple_presenter'
|
8
|
-
require 'support/presenters/missing_for_presenter'
|
9
|
-
require 'support/presenters/missing_initialize_presenter'
|
10
|
-
require 'support/presenters/missing_content_presenter'
|
11
|
-
require 'support/presenters/missing_attributes_presenter'
|
12
|
-
|
13
|
-
describe Shortcode::Presenter do
|
14
|
-
|
15
|
-
let(:configuration) { Shortcode.singleton.send(:configuration) }
|
16
|
-
let(:simple_quote) { load_fixture :simple_quote }
|
17
|
-
let(:item) { load_fixture :item }
|
18
|
-
|
19
|
-
describe "using a custom presenter" do
|
20
|
-
|
21
|
-
let(:presenter_output) { load_fixture :simple_quote_presenter_output, :html }
|
22
|
-
let(:attributes_output) { load_fixture :simple_quote_presenter_attributes_output, :html }
|
23
|
-
|
24
|
-
before do
|
25
|
-
Shortcode.register_presenter MyPresenter
|
26
|
-
end
|
27
|
-
|
28
|
-
it "uses the custom attributes" do
|
29
|
-
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(presenter_output)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "passes through additional attributes" do
|
33
|
-
expect(Shortcode.process(simple_quote, { title: 'Additional attribute title' }).gsub("\n",'')).to eq(attributes_output)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "using a single presenter for multiple shortcodes" do
|
39
|
-
let(:quote_presenter_output) { load_fixture :simple_quote_presenter_output, :html }
|
40
|
-
let(:item_presenter_output) { load_fixture :item_presenter_output, :html }
|
41
|
-
|
42
|
-
let(:quote_attributes_output) { load_fixture :simple_quote_presenter_attributes_output, :html }
|
43
|
-
let(:item_attributes_output) { load_fixture :item_presenter_attributes_output, :html }
|
44
|
-
|
45
|
-
before do
|
46
|
-
Shortcode.register_presenter MultiplePresenter
|
47
|
-
end
|
48
|
-
|
49
|
-
it "uses the custom attributes" do
|
50
|
-
expect(Shortcode.process(simple_quote ).gsub("\n",'')).to eq(quote_presenter_output)
|
51
|
-
expect(Shortcode.process(item ).gsub("\n",'')).to eq(item_presenter_output)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "passes through additional attributes" do
|
55
|
-
expect(Shortcode.process(simple_quote, { title: 'Additional attribute title' }).gsub("\n",'')).to eq(quote_attributes_output)
|
56
|
-
expect(Shortcode.process(item, { title: 'Additional attribute title' }).gsub("\n",'')).to eq(item_attributes_output)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
context "presenter registration" do
|
62
|
-
|
63
|
-
describe "registering a single presenter" do
|
64
|
-
|
65
|
-
before do
|
66
|
-
Shortcode.register_presenter MyPresenter
|
67
|
-
end
|
68
|
-
|
69
|
-
it "adds the presenter to the list" do
|
70
|
-
expect(configuration.presenters).to include(MyPresenter.for)
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "registering multiple presenters" do
|
76
|
-
|
77
|
-
before do
|
78
|
-
Shortcode.register_presenter(MyPresenter, OtherPresenter)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "adds the presenter to the list" do
|
82
|
-
expect(configuration.presenters).to include(MyPresenter.for)
|
83
|
-
expect(configuration.presenters).to include(OtherPresenter.for)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
context "presenter validation" do
|
91
|
-
|
92
|
-
describe "missing #for class method" do
|
93
|
-
|
94
|
-
it "raises an exception" do
|
95
|
-
expect { Shortcode.register_presenter MissingForPresenter }.to raise_error(ArgumentError, "The presenter must define the class method #for")
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "missing #initialize method" do
|
101
|
-
|
102
|
-
it "raises an exception" do
|
103
|
-
expect { Shortcode.register_presenter MissingInitializePresenter }.to raise_error(ArgumentError, "The presenter must define an initialize method")
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "missing #content method" do
|
109
|
-
|
110
|
-
it "raises an exception" do
|
111
|
-
expect { Shortcode.register_presenter MissingContentPresenter }.to raise_error(ArgumentError, "The presenter must define the method #content")
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "missing #attributes method" do
|
117
|
-
|
118
|
-
it "raises an exception" do
|
119
|
-
expect { Shortcode.register_presenter MissingAttributesPresenter }.to raise_error(ArgumentError, "The presenter must define the method #attributes")
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
data/spec/tag_spec.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shortcode::Tag do
|
4
|
-
let(:configuration) { Shortcode.singleton.send(:configuration) }
|
5
|
-
|
6
|
-
context "when the template file is missing" do
|
7
|
-
|
8
|
-
let(:tag) { Shortcode::Tag.new('doesnt_exist', configuration) }
|
9
|
-
|
10
|
-
it "raises a TemplateNotFound error when the file doesn't exists" do
|
11
|
-
expect { tag.render }.to raise_error(Shortcode::TemplateNotFound)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when an unsupported template parser is specified" do
|
17
|
-
|
18
|
-
let(:tag) { Shortcode::Tag.new('quote', configuration) }
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
Shortcode.setup do |config|
|
22
|
-
config.template_parser = :something_crazy
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "raises a TemplateNotFound error when the file doesn't exists" do
|
27
|
-
expect { tag.render }.to raise_error(Shortcode::TemplateParserNotSupported)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
context "templates from strings" do
|
33
|
-
|
34
|
-
let(:tag) { Shortcode::Tag.new('from_string', configuration, [{ key: 'string', value: 'batman' }]) }
|
35
|
-
|
36
|
-
before(:each) do
|
37
|
-
Shortcode.setup do |config|
|
38
|
-
config.templates = {
|
39
|
-
from_string: '<p><%= @attributes[:string] %></p>'
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "renders a template from a string" do
|
45
|
-
expect(tag.render).to eq('<p>batman</p>')
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when the template is missing from the config" do
|
51
|
-
|
52
|
-
let(:tag) { Shortcode::Tag.new('missing', configuration, [{ key: 'string', value: 'batman' }]) }
|
53
|
-
|
54
|
-
before(:each) do
|
55
|
-
Shortcode.setup do |config|
|
56
|
-
config.templates = {
|
57
|
-
from_string: '<p><%= @attributes[:string] %></p>'
|
58
|
-
}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "raises an error" do
|
63
|
-
expect { tag.render }.to raise_error(Shortcode::TemplateNotFound)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when templates exist both in configuration and file system" do
|
69
|
-
let(:tag) { Shortcode::Tag.new('quote', configuration ) }
|
70
|
-
|
71
|
-
before(:each) do
|
72
|
-
configuration.templates[:quote] = '<p><%= @content %></p>'
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'uses the configuration template when check_config_templates_first is true' do
|
76
|
-
expect(tag.markup).to eq('<p><%= @content %></p>')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'uses the file system template when check_config_templates_first is false' do
|
80
|
-
configuration.check_config_templates_first = false
|
81
|
-
|
82
|
-
expect(tag.markup).to eq(File.open('spec/support/templates/erb/quote.html.erb').read)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|