shortcode 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +7 -9
- data/Appraisals +8 -8
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +41 -55
- data/README.md +66 -27
- data/gemfiles/rails_4.1.gemfile +3 -3
- data/gemfiles/rails_4.2.gemfile +3 -3
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_5.1.gemfile +8 -0
- data/lib/shortcode.rb +26 -12
- data/lib/shortcode/configuration.rb +20 -8
- data/lib/shortcode/exceptions.rb +1 -1
- data/lib/shortcode/parser.rb +59 -29
- data/lib/shortcode/presenter.rb +19 -26
- data/lib/shortcode/processor.rb +8 -9
- data/lib/shortcode/tag.rb +44 -31
- data/lib/shortcode/template_binding.rb +19 -18
- data/lib/shortcode/transformer.rb +34 -13
- data/lib/shortcode/version.rb +2 -2
- data/shortcode.gemspec +6 -6
- data/spec/parser_spec.rb +2 -2
- data/spec/presenter_spec.rb +4 -4
- data/spec/shortcode_spec.rb +25 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/tag_spec.rb +23 -4
- data/spec/template_parsers_spec.rb +1 -1
- data/spec/transformer_spec.rb +3 -3
- metadata +17 -17
- data/gemfiles/rails_3.2.gemfile +0 -8
- data/gemfiles/rails_4.0.gemfile +0 -8
data/lib/shortcode/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "1.
|
1
|
+
class Shortcode
|
2
|
+
VERSION = "1.2.0"
|
3
3
|
end
|
data/shortcode.gemspec
CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "parslet", "1.
|
21
|
+
spec.add_dependency "parslet", "1.8.0"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
24
|
-
spec.add_development_dependency "rake", "~>
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.
|
26
|
-
spec.add_development_dependency "coveralls", "~> 0"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
26
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
27
27
|
spec.add_development_dependency "slim", "~> 3.0"
|
28
|
-
spec.add_development_dependency "haml", "~>
|
28
|
+
spec.add_development_dependency "haml", "~> 5.0"
|
29
29
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'parslet/rig/rspec'
|
|
3
3
|
require 'pp'
|
4
4
|
|
5
5
|
describe Shortcode::Parser do
|
6
|
-
|
7
|
-
let(:parser) { Shortcode::Parser.new }
|
6
|
+
configuration = Shortcode.singleton.send(:configuration)
|
7
|
+
let(:parser) { Shortcode::Parser.new(configuration) }
|
8
8
|
|
9
9
|
let(:simple_quote) { load_fixture :simple_quote }
|
10
10
|
let(:full_quote) { load_fixture :full_quote }
|
data/spec/presenter_spec.rb
CHANGED
@@ -12,6 +12,7 @@ require 'support/presenters/missing_attributes_presenter'
|
|
12
12
|
|
13
13
|
describe Shortcode::Presenter do
|
14
14
|
|
15
|
+
let(:configuration) { Shortcode.singleton.send(:configuration) }
|
15
16
|
let(:simple_quote) { load_fixture :simple_quote }
|
16
17
|
let(:item) { load_fixture :item }
|
17
18
|
|
@@ -35,7 +36,6 @@ describe Shortcode::Presenter do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
describe "using a single presenter for multiple shortcodes" do
|
38
|
-
|
39
39
|
let(:quote_presenter_output) { load_fixture :simple_quote_presenter_output, :html }
|
40
40
|
let(:item_presenter_output) { load_fixture :item_presenter_output, :html }
|
41
41
|
|
@@ -67,7 +67,7 @@ describe Shortcode::Presenter do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "adds the presenter to the list" do
|
70
|
-
expect(
|
70
|
+
expect(configuration.presenters).to include(MyPresenter.for)
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -79,8 +79,8 @@ describe Shortcode::Presenter do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "adds the presenter to the list" do
|
82
|
-
expect(
|
83
|
-
expect(
|
82
|
+
expect(configuration.presenters).to include(MyPresenter.for)
|
83
|
+
expect(configuration.presenters).to include(OtherPresenter.for)
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
data/spec/shortcode_spec.rb
CHANGED
@@ -54,4 +54,29 @@ describe Shortcode do
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
+
context "multiple instances" do
|
58
|
+
let(:shortcode1) { Shortcode.new }
|
59
|
+
let(:shortcode2) { Shortcode.new }
|
60
|
+
|
61
|
+
it "allows having multiple Shortcode instances that have independent configurations" do
|
62
|
+
expect(shortcode1.send(:configuration)).to_not be(shortcode2.send(:configuration))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "uses the shortcode instance's configuration to process shortcodes" do
|
66
|
+
shortcode1.setup do |config|
|
67
|
+
config.self_closing_tags << :quote
|
68
|
+
config.templates = { quote: 'i am from shortcode 1' }
|
69
|
+
end
|
70
|
+
|
71
|
+
shortcode2.setup do |config|
|
72
|
+
config.self_closing_tags << :quote
|
73
|
+
config.templates = { quote: 'i am from shortcode 2' }
|
74
|
+
end
|
75
|
+
|
76
|
+
expect(shortcode1.process('[quote]')).to eq('i am from shortcode 1')
|
77
|
+
expect(shortcode2.process('[quote]')).to eq('i am from shortcode 2')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
57
82
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,17 +16,19 @@ Slim::Engine.set_options attr_quote: "'"
|
|
16
16
|
|
17
17
|
RSpec.configure do |config|
|
18
18
|
config.order = "random"
|
19
|
+
config.color = true
|
19
20
|
|
20
21
|
config.before(:each) do
|
21
|
-
Shortcode::Presenter.presenters = {}
|
22
22
|
Shortcode.setup do |config|
|
23
23
|
config.template_parser = :erb
|
24
24
|
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
25
|
-
config.templates =
|
25
|
+
config.templates = {}
|
26
|
+
config.check_config_templates_first = true
|
26
27
|
config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper, :custom_helper]
|
27
28
|
config.self_closing_tags = [:timeline_event, :timeline_info]
|
28
29
|
config.attribute_quote_type = '"'
|
29
30
|
config.use_attribute_quotes = true
|
31
|
+
config.presenters = {}
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/spec/tag_spec.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Shortcode::Tag do
|
4
|
+
let(:configuration) { Shortcode.singleton.send(:configuration) }
|
4
5
|
|
5
6
|
context "when the template file is missing" do
|
6
7
|
|
7
|
-
let(:tag) { Shortcode::Tag.new('doesnt_exist') }
|
8
|
+
let(:tag) { Shortcode::Tag.new('doesnt_exist', configuration) }
|
8
9
|
|
9
10
|
it "raises a TemplateNotFound error when the file doesn't exists" do
|
10
11
|
expect { tag.render }.to raise_error(Shortcode::TemplateNotFound)
|
@@ -14,7 +15,7 @@ describe Shortcode::Tag do
|
|
14
15
|
|
15
16
|
context "when an unsupported template parser is specified" do
|
16
17
|
|
17
|
-
let(:tag) { Shortcode::Tag.new('quote') }
|
18
|
+
let(:tag) { Shortcode::Tag.new('quote', configuration) }
|
18
19
|
|
19
20
|
before(:each) do
|
20
21
|
Shortcode.setup do |config|
|
@@ -30,7 +31,7 @@ describe Shortcode::Tag do
|
|
30
31
|
|
31
32
|
context "templates from strings" do
|
32
33
|
|
33
|
-
let(:tag) { Shortcode::Tag.new('from_string', [{ key: 'string', value: 'batman' }]) }
|
34
|
+
let(:tag) { Shortcode::Tag.new('from_string', configuration, [{ key: 'string', value: 'batman' }]) }
|
34
35
|
|
35
36
|
before(:each) do
|
36
37
|
Shortcode.setup do |config|
|
@@ -48,7 +49,7 @@ describe Shortcode::Tag do
|
|
48
49
|
|
49
50
|
context "when the template is missing from the config" do
|
50
51
|
|
51
|
-
let(:tag) { Shortcode::Tag.new('missing', [{ key: 'string', value: 'batman' }]) }
|
52
|
+
let(:tag) { Shortcode::Tag.new('missing', configuration, [{ key: 'string', value: 'batman' }]) }
|
52
53
|
|
53
54
|
before(:each) do
|
54
55
|
Shortcode.setup do |config|
|
@@ -64,4 +65,22 @@ describe Shortcode::Tag do
|
|
64
65
|
|
65
66
|
end
|
66
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
|
+
|
67
86
|
end
|
@@ -23,7 +23,7 @@ describe "template parsers" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "can render a template" do
|
26
|
-
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
26
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'').gsub('> <', '><')).to eq(simple_quote_output)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/spec/transformer_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'parslet/rig/rspec'
|
|
3
3
|
require 'pp'
|
4
4
|
|
5
5
|
describe Shortcode do
|
6
|
-
|
7
|
-
let(:parser) { Shortcode::Parser.new }
|
8
|
-
let(:transformer) { Shortcode::Transformer.new }
|
6
|
+
configuration = Shortcode.singleton.send(:configuration)
|
7
|
+
let(:parser) { Shortcode::Parser.new(configuration) }
|
8
|
+
let(:transformer) { Shortcode::Transformer.new(configuration) }
|
9
9
|
|
10
10
|
let(:simple_quote) { load_fixture :simple_quote }
|
11
11
|
let(:full_quote) { load_fixture :full_quote }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shortcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Dyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.15'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.15'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.6'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: coveralls
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '0.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '0.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: slim
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '5.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '5.0'
|
111
111
|
description: Gem for parsing wordpress style shortcodes
|
112
112
|
email:
|
113
113
|
- jamie@kernowsoul.com
|
@@ -125,10 +125,10 @@ files:
|
|
125
125
|
- LICENSE.txt
|
126
126
|
- README.md
|
127
127
|
- Rakefile
|
128
|
-
- gemfiles/rails_3.2.gemfile
|
129
|
-
- gemfiles/rails_4.0.gemfile
|
130
128
|
- gemfiles/rails_4.1.gemfile
|
131
129
|
- gemfiles/rails_4.2.gemfile
|
130
|
+
- gemfiles/rails_5.0.gemfile
|
131
|
+
- gemfiles/rails_5.1.gemfile
|
132
132
|
- lib/shortcode.rb
|
133
133
|
- lib/shortcode/configuration.rb
|
134
134
|
- lib/shortcode/exceptions.rb
|
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
223
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.
|
224
|
+
rubygems_version: 2.6.11
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Gem for parsing wordpress style shortcodes in ruby projects
|
data/gemfiles/rails_3.2.gemfile
DELETED