shortcode 0.3.3 → 0.4.0
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.
- data/Gemfile.lock +16 -12
- data/README.md +19 -12
- data/lib/shortcode.rb +5 -3
- data/lib/shortcode/configuration.rb +1 -15
- data/lib/shortcode/tag.rb +4 -5
- data/lib/shortcode/version.rb +1 -1
- data/shortcode.gemspec +2 -2
- data/spec/parser_spec.rb +20 -20
- data/spec/presenter_spec.rb +2 -2
- data/spec/rails_helpers_spec.rb +10 -10
- data/spec/shortcode_spec.rb +2 -9
- data/spec/spec_helper.rb +6 -6
- data/spec/support/fixtures.rb +3 -1
- data/spec/support/templates/erb/collapsible_list.html.erb +3 -0
- data/spec/support/templates/erb/item.html.erb +4 -0
- data/spec/support/templates/erb/quote.html.erb +2 -1
- data/spec/support/templates/erb/timeline_event.html.erb +17 -0
- data/spec/support/templates/erb/timeline_info.html.erb +15 -0
- data/spec/support/templates/erb/timeline_person.html.erb +23 -0
- data/spec/tag_spec.rb +1 -3
- data/spec/template_parsers_spec.rb +8 -31
- data/spec/transformer_spec.rb +9 -16
- metadata +32 -34
- data/spec/support/custom_expectations/write_expectation.rb +0 -62
- data/spec/support/templates/haml/collapsible_list.html.haml +0 -2
- data/spec/support/templates/haml/item.html.haml +0 -3
- data/spec/support/templates/haml/timeline_event.html.haml +0 -10
- data/spec/support/templates/haml/timeline_info.html.haml +0 -8
- data/spec/support/templates/haml/timeline_person.html.haml +0 -15
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shortcode (0.
|
5
|
-
haml (~> 4.0)
|
4
|
+
shortcode (0.4.0)
|
6
5
|
parslet (= 1.6.0)
|
7
6
|
|
8
7
|
GEM
|
@@ -19,7 +18,7 @@ GEM
|
|
19
18
|
simplecov (>= 0.7)
|
20
19
|
term-ansicolor
|
21
20
|
thor
|
22
|
-
diff-lcs (1.2.
|
21
|
+
diff-lcs (1.2.5)
|
23
22
|
docile (1.1.3)
|
24
23
|
haml (4.0.5)
|
25
24
|
tilt
|
@@ -30,14 +29,18 @@ GEM
|
|
30
29
|
rake (10.1.0)
|
31
30
|
rest-client (1.6.7)
|
32
31
|
mime-types (>= 1.16)
|
33
|
-
rspec (
|
34
|
-
rspec-core (~>
|
35
|
-
rspec-expectations (~>
|
36
|
-
rspec-mocks (~>
|
37
|
-
rspec-core (
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
rspec (3.0.0)
|
33
|
+
rspec-core (~> 3.0.0)
|
34
|
+
rspec-expectations (~> 3.0.0)
|
35
|
+
rspec-mocks (~> 3.0.0)
|
36
|
+
rspec-core (3.0.0)
|
37
|
+
rspec-support (~> 3.0.0)
|
38
|
+
rspec-expectations (3.0.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.0.0)
|
41
|
+
rspec-mocks (3.0.0)
|
42
|
+
rspec-support (~> 3.0.0)
|
43
|
+
rspec-support (3.0.0)
|
41
44
|
simplecov (0.8.2)
|
42
45
|
docile (~> 1.1.0)
|
43
46
|
multi_json
|
@@ -60,7 +63,8 @@ DEPENDENCIES
|
|
60
63
|
appraisal (= 1.0.0.beta3)
|
61
64
|
bundler (~> 1.3)
|
62
65
|
coveralls
|
66
|
+
haml (~> 4.0)
|
63
67
|
rake
|
64
|
-
rspec
|
68
|
+
rspec (~> 3.0.0)
|
65
69
|
shortcode!
|
66
70
|
slim (~> 2.0)
|
data/README.md
CHANGED
@@ -46,10 +46,10 @@ Shortcode.process("[quote]Hello World[/quote]")
|
|
46
46
|
Shortcode.setup do |config|
|
47
47
|
|
48
48
|
# the template parser to use
|
49
|
-
config.template_parser = :
|
49
|
+
config.template_parser = :erb # :erb, :haml, :slim supported, :erb is default
|
50
50
|
|
51
51
|
# location of the template files, default is "app/views/shortcode_templates"
|
52
|
-
config.template_path = "support/templates/
|
52
|
+
config.template_path = "support/templates/erb"
|
53
53
|
|
54
54
|
# a hash of templates passed as strings, if this is set it overrides the
|
55
55
|
# above template_path option. The default is nil
|
@@ -68,19 +68,26 @@ end
|
|
68
68
|
|
69
69
|
### Templates
|
70
70
|
|
71
|
-
Each shortcode tag needs a template in order to translate the shortcode into html (or other output). Templates can be written in
|
71
|
+
Each shortcode tag needs a template in order to translate the shortcode into html (or other output). Templates can be written in erb, haml or slim and work in
|
72
72
|
a similar way to views in Rails. The main content of a tag is passed via the instance variable `@content`. Any attributes defined on a tag are passed in via an `@attributes` hash, shortcodes can have any number of attributes. For instance a quote shortcode might look like this:
|
73
73
|
|
74
74
|
[quote author="Homer Simpson"]Doh![/quote]
|
75
75
|
|
76
|
-
And the
|
77
|
-
|
78
|
-
```
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
And the erb template to render the shortcode
|
77
|
+
|
78
|
+
```erb
|
79
|
+
<blockquote>
|
80
|
+
<p class='quotation'>
|
81
|
+
<%= @content %>
|
82
|
+
</p>
|
83
|
+
<% if @attributes[:author] %>
|
84
|
+
<p class='citation'>
|
85
|
+
<span class='author'>
|
86
|
+
<%= @attributes[:author] %>
|
87
|
+
</span>
|
88
|
+
</p>
|
89
|
+
<% end %>
|
90
|
+
</blockquote>
|
84
91
|
```
|
85
92
|
|
86
93
|
If using the gem within a Rails project you can use the Rails helper methods within templates.
|
@@ -101,7 +108,7 @@ block as strings.
|
|
101
108
|
|
102
109
|
#### Templates loaded from the file system
|
103
110
|
|
104
|
-
Simply create files with the extension or .haml or .
|
111
|
+
Simply create files with the extension or .erb, .haml, or .slim with a filename the same as the shortcode tag, e.g. gallery.html.erb would render a [gallery] shortcode tag. The default
|
105
112
|
location for template files is `app/views/shortcode_templates`, if you want to load tempaltes from a different location use the `template_path` config option.
|
106
113
|
|
107
114
|
#### Templates set as configuration options
|
data/lib/shortcode.rb
CHANGED
@@ -1,20 +1,7 @@
|
|
1
1
|
class Shortcode::Configuration
|
2
|
-
# This stores if the parser has been set in a configuration block so that deprication
|
3
|
-
# warnings can be issued
|
4
|
-
attr_accessor :parser_set
|
5
|
-
|
6
|
-
def haml_deprecation_warning
|
7
|
-
"[DEPRECATION] HAML will no longer be the default template parser in version 0.4 of Shortcode. A HAML template has been used without explicitly specifying HAML as the template parser in a setup block. Please set config.template_parser = :haml to suppress this warning"
|
8
|
-
end
|
9
|
-
|
10
2
|
# Sets the template parser to use, supports :erb, :haml, and :slim, default is :haml
|
11
3
|
attr_accessor :template_parser
|
12
4
|
|
13
|
-
def template_parser=(parser)
|
14
|
-
@parser_set = true
|
15
|
-
@template_parser = parser
|
16
|
-
end
|
17
|
-
|
18
5
|
# Sets the path to search for template files
|
19
6
|
attr_accessor :template_path
|
20
7
|
|
@@ -31,12 +18,11 @@ class Shortcode::Configuration
|
|
31
18
|
attr_accessor :quotes
|
32
19
|
|
33
20
|
def initialize
|
34
|
-
@template_parser = :
|
21
|
+
@template_parser = :erb
|
35
22
|
@template_path = "app/views/shortcode_templates"
|
36
23
|
@templates = nil
|
37
24
|
@block_tags = []
|
38
25
|
@self_closing_tags = []
|
39
26
|
@quotes = '"'
|
40
|
-
@parser_set = false
|
41
27
|
end
|
42
28
|
end
|
data/lib/shortcode/tag.rb
CHANGED
@@ -29,13 +29,12 @@ class Shortcode::Tag
|
|
29
29
|
|
30
30
|
def render_template
|
31
31
|
case Shortcode.configuration.template_parser
|
32
|
-
when :slim
|
33
|
-
Slim::Template.new { markup }.render(self)
|
34
|
-
when :haml
|
35
|
-
warn Shortcode.configuration.haml_deprecation_warning unless Shortcode.configuration.parser_set
|
36
|
-
Haml::Engine.new(markup, ugly: true).render(binding)
|
37
32
|
when :erb
|
38
33
|
ERB.new(markup).result(binding)
|
34
|
+
when :haml
|
35
|
+
Haml::Engine.new(markup, ugly: true).render(binding)
|
36
|
+
when :slim
|
37
|
+
Slim::Template.new { markup }.render(self)
|
39
38
|
else
|
40
39
|
raise Shortcode::TemplateParserNotSupported, Shortcode.configuration.template_parser
|
41
40
|
end
|
data/lib/shortcode/version.rb
CHANGED
data/shortcode.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "parslet", "1.6.0"
|
22
|
-
spec.add_dependency "haml", "~> 4.0"
|
23
22
|
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
24
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0.0"
|
27
26
|
spec.add_development_dependency "coveralls"
|
28
27
|
spec.add_development_dependency "slim", "~> 2.0"
|
28
|
+
spec.add_development_dependency "haml", "~> 4.0"
|
29
29
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Shortcode::Parser do
|
|
21
21
|
|
22
22
|
it "parses quote shortcodes" do
|
23
23
|
quotes.each do |string|
|
24
|
-
parser.
|
24
|
+
expect(parser).to parse(string)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -32,7 +32,7 @@ describe Shortcode::Parser do
|
|
32
32
|
|
33
33
|
quotes.each do |string|
|
34
34
|
# Change double quotes to single quotes in the fixture
|
35
|
-
parser.
|
35
|
+
expect(parser).to parse(string.gsub '"', "'")
|
36
36
|
end
|
37
37
|
|
38
38
|
# Reset configuration to default
|
@@ -43,18 +43,18 @@ describe Shortcode::Parser do
|
|
43
43
|
|
44
44
|
it "parses list shortcodes" do
|
45
45
|
collapsible_lists.each do |string|
|
46
|
-
parser.
|
46
|
+
expect(parser).to parse(string)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
it "parses timeline shortcodes" do
|
51
51
|
timelines.each do |string|
|
52
|
-
parser.
|
52
|
+
expect(parser).to parse(string)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
it "parses complex nested shortcodes" do
|
57
|
-
parser.
|
57
|
+
expect(parser).to parse(complex_snippet)
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "parsed strings" do
|
@@ -64,7 +64,7 @@ describe Shortcode::Parser do
|
|
64
64
|
let(:parsed_object) { parser.parse(simple_quote) }
|
65
65
|
|
66
66
|
it "created the expected object" do
|
67
|
-
parsed_object[:body].
|
67
|
+
expect(parsed_object[:body]).to eq([{ open: "quote", options: [], inner: [{ text: "hello" }], close: "quote" }])
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
@@ -74,7 +74,7 @@ describe Shortcode::Parser do
|
|
74
74
|
let(:parsed_object) { parser.parse(full_quote) }
|
75
75
|
|
76
76
|
it "created the expected object" do
|
77
|
-
parsed_object[:body].
|
77
|
+
expect(parsed_object[:body]).to eq([{
|
78
78
|
open: "quote",
|
79
79
|
options: [
|
80
80
|
{ key: "author", value: "Jamie Dyer" },
|
@@ -82,7 +82,7 @@ describe Shortcode::Parser do
|
|
82
82
|
],
|
83
83
|
inner: [{ text: "A quote" }],
|
84
84
|
close: "quote"
|
85
|
-
}]
|
85
|
+
}])
|
86
86
|
end
|
87
87
|
|
88
88
|
end
|
@@ -92,7 +92,7 @@ describe Shortcode::Parser do
|
|
92
92
|
let(:parsed_object) { parser.parse(quote_with_extras) }
|
93
93
|
|
94
94
|
it "created the expected object" do
|
95
|
-
parsed_object[:body].
|
95
|
+
expect(parsed_object[:body]).to eq([
|
96
96
|
{ text: "Blah blah " },
|
97
97
|
{
|
98
98
|
open: "quote",
|
@@ -103,7 +103,7 @@ describe Shortcode::Parser do
|
|
103
103
|
close: "quote"
|
104
104
|
},
|
105
105
|
{ text: "<br> blah blah\n" }
|
106
|
-
]
|
106
|
+
])
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
@@ -113,7 +113,7 @@ describe Shortcode::Parser do
|
|
113
113
|
let(:parsed_object) { parser.parse(simple_list) }
|
114
114
|
|
115
115
|
it "created the expected object" do
|
116
|
-
parsed_object[:body].
|
116
|
+
expect(parsed_object[:body]).to eq([{
|
117
117
|
open: "collapsible_list",
|
118
118
|
options: [],
|
119
119
|
inner: [{
|
@@ -135,7 +135,7 @@ describe Shortcode::Parser do
|
|
135
135
|
close: "item"
|
136
136
|
}],
|
137
137
|
close: "collapsible_list"
|
138
|
-
}]
|
138
|
+
}])
|
139
139
|
end
|
140
140
|
|
141
141
|
end
|
@@ -145,14 +145,14 @@ describe Shortcode::Parser do
|
|
145
145
|
let(:parsed_object) { parser.parse(timeline_event) }
|
146
146
|
|
147
147
|
it "created the expected object" do
|
148
|
-
parsed_object[:body].
|
148
|
+
expect(parsed_object[:body]).to eq([{
|
149
149
|
open_close: "timeline_event",
|
150
150
|
options: [
|
151
151
|
{ key: "date", value: "March 2013" },
|
152
152
|
{ key: "title", value: "a title" },
|
153
153
|
{ key: "link", value: "http://blah.com" }
|
154
154
|
]
|
155
|
-
}]
|
155
|
+
}])
|
156
156
|
end
|
157
157
|
|
158
158
|
end
|
@@ -162,13 +162,13 @@ describe Shortcode::Parser do
|
|
162
162
|
let(:parsed_object) { parser.parse(timeline_info) }
|
163
163
|
|
164
164
|
it "created the expected object" do
|
165
|
-
parsed_object[:body].
|
165
|
+
expect(parsed_object[:body]).to eq([{
|
166
166
|
open_close: "timeline_info",
|
167
167
|
options: [
|
168
168
|
{ key: "date", value: "Feb 2013" },
|
169
169
|
{ key: "title", value: "Something amazing" }
|
170
170
|
]
|
171
|
-
}]
|
171
|
+
}])
|
172
172
|
end
|
173
173
|
|
174
174
|
end
|
@@ -178,7 +178,7 @@ describe Shortcode::Parser do
|
|
178
178
|
let(:parsed_object) { parser.parse(timeline_person) }
|
179
179
|
|
180
180
|
it "created the expected object" do
|
181
|
-
parsed_object[:body].
|
181
|
+
expect(parsed_object[:body]).to eq([{
|
182
182
|
open: "timeline_person",
|
183
183
|
options: [
|
184
184
|
{ key: "date", value: "Jan 2012" },
|
@@ -190,7 +190,7 @@ describe Shortcode::Parser do
|
|
190
190
|
],
|
191
191
|
inner: [{ text: "A bit of body copy\nwith a newline\n" }],
|
192
192
|
close: "timeline_person"
|
193
|
-
}]
|
193
|
+
}])
|
194
194
|
end
|
195
195
|
|
196
196
|
end
|
@@ -200,7 +200,7 @@ describe Shortcode::Parser do
|
|
200
200
|
let(:parsed_object) { parser.parse(complex_snippet) }
|
201
201
|
|
202
202
|
it "created the expected object" do
|
203
|
-
parsed_object[:body].
|
203
|
+
expect(parsed_object[:body]).to eq([{
|
204
204
|
text: "<h3>A page title</h3>\n<p>Some text</p>\n"},
|
205
205
|
{
|
206
206
|
open: "collapsible_list",
|
@@ -244,7 +244,7 @@ describe Shortcode::Parser do
|
|
244
244
|
close: "collapsible_list"
|
245
245
|
},
|
246
246
|
{ text: "<p>Some more text</p>\n" }
|
247
|
-
]
|
247
|
+
])
|
248
248
|
end
|
249
249
|
end
|
250
250
|
end
|
data/spec/presenter_spec.rb
CHANGED
@@ -36,11 +36,11 @@ describe Shortcode::Presenter do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "uses the custom attributes" do
|
39
|
-
Shortcode.process(simple_quote).gsub("\n",'').
|
39
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(presenter_output)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "passes through additional attributes" do
|
43
|
-
Shortcode.process(simple_quote, { title: 'Additional attribute title' }).gsub("\n",'').
|
43
|
+
expect(Shortcode.process(simple_quote, { title: 'Additional attribute title' }).gsub("\n",'')).to eq(attributes_output)
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
data/spec/rails_helpers_spec.rb
CHANGED
@@ -10,23 +10,23 @@ describe "rails helpers" do
|
|
10
10
|
|
11
11
|
describe "erb" do
|
12
12
|
|
13
|
-
before(:each) do
|
14
|
-
Shortcode.setup do |config|
|
15
|
-
config.template_parser = :erb
|
16
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
13
|
it "are accessible within erb templates" do
|
21
|
-
Shortcode.process(template).gsub("\n",'').
|
14
|
+
expect(Shortcode.process(template).gsub("\n",'')).to eq(erb_output)
|
22
15
|
end
|
23
16
|
|
24
17
|
end
|
25
18
|
|
26
19
|
describe "haml" do
|
27
20
|
|
21
|
+
before(:each) do
|
22
|
+
Shortcode.setup do |config|
|
23
|
+
config.template_parser = :haml
|
24
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
28
|
it "are accessible within haml templates" do
|
29
|
-
Shortcode.process(template).gsub("\n",'').
|
29
|
+
expect(Shortcode.process(template).gsub("\n",'')).to eq(haml_output)
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -41,7 +41,7 @@ describe "rails helpers" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "are accessible within slim templates" do
|
44
|
-
Shortcode.process(template).gsub("\n",'').
|
44
|
+
expect(Shortcode.process(template).gsub("\n",'')).to eq(slim_output)
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
data/spec/shortcode_spec.rb
CHANGED
@@ -10,22 +10,15 @@ describe Shortcode do
|
|
10
10
|
context "simple_quote" do
|
11
11
|
|
12
12
|
it "converts into html" do
|
13
|
-
Shortcode.process(simple_quote).
|
13
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context "erb templates" do
|
19
19
|
|
20
|
-
before(:each) do
|
21
|
-
Shortcode.setup do |config|
|
22
|
-
config.template_parser = :erb
|
23
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
20
|
it "converts into html" do
|
28
|
-
Shortcode.process(simple_quote).gsub("\n",'').
|
21
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
29
22
|
end
|
30
23
|
end
|
31
24
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
if ENV["CI"]
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
end
|
5
7
|
|
6
8
|
require 'rspec'
|
7
9
|
require 'rails'
|
8
10
|
require 'action_view'
|
9
11
|
require 'shortcode'
|
10
12
|
require 'support/fixtures'
|
11
|
-
require 'support/custom_expectations/write_expectation'
|
12
13
|
|
13
14
|
# Set slim's attribute quotes to use single quotes so it's the same as haml
|
14
15
|
Slim::Engine.set_default_options attr_quote: "'"
|
@@ -19,9 +20,8 @@ RSpec.configure do |config|
|
|
19
20
|
config.before(:each) do
|
20
21
|
Shortcode.presenters = {}
|
21
22
|
Shortcode.setup do |config|
|
22
|
-
config.template_parser = :
|
23
|
-
config.
|
24
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
23
|
+
config.template_parser = :erb
|
24
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
25
25
|
config.templates = nil
|
26
26
|
config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper]
|
27
27
|
config.self_closing_tags = [:timeline_event, :timeline_info]
|
data/spec/support/fixtures.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
2
|
|
3
3
|
def load_fixture(name, type='txt')
|
4
|
-
|
4
|
+
type = type.to_s
|
5
|
+
string = File.read(File.join(File.dirname(__FILE__), 'fixtures', "#{name}.#{type}"))
|
6
|
+
type == 'txt' ? string : string.gsub("\n",'')
|
5
7
|
end
|
6
8
|
|
7
9
|
end
|
@@ -5,7 +5,8 @@
|
|
5
5
|
<% if @attributes[:author] %>
|
6
6
|
<span class='author'><%= @attributes[:author] %></span>
|
7
7
|
<% end %>
|
8
|
-
<% if @attributes[:title]
|
8
|
+
<% if @attributes[:title] %>
|
9
|
+
<span class='position'><%= @attributes[:title] %></span>
|
9
10
|
<% end %>
|
10
11
|
</p>
|
11
12
|
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class='timeline'>
|
2
|
+
<table>
|
3
|
+
<tbody>
|
4
|
+
<tr>
|
5
|
+
<th scope='row'>
|
6
|
+
<%= @attributes[:date] %>
|
7
|
+
</th>
|
8
|
+
<td class='event'>
|
9
|
+
<span class='description'><%= @attributes[:title] %></span>
|
10
|
+
<% if @attributes[:link] %>
|
11
|
+
<a class='read_more' href='<%= @attributes[:link] %>'>Read More</a>
|
12
|
+
<% end %>
|
13
|
+
</td>
|
14
|
+
</tr>
|
15
|
+
</tbody>
|
16
|
+
</table>
|
17
|
+
</div>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<div class='timeline'>
|
2
|
+
<table>
|
3
|
+
<tbody>
|
4
|
+
<tr>
|
5
|
+
<th scope='row'>
|
6
|
+
<%= @attributes[:date] %>
|
7
|
+
</th>
|
8
|
+
<td class='team_news'>
|
9
|
+
<img src='<%= @attributes[:image] %>'>
|
10
|
+
<h4><%= @attributes[:title] %></h4>
|
11
|
+
<span class='name'><%= @attributes[:name] %></span>
|
12
|
+
<span class='position'><%= @attributes[:position] %></span>
|
13
|
+
<% if @attributes[:link] %>
|
14
|
+
<a class='read_more' href='<%= @attributes[:link] %>'>View Profile</a>
|
15
|
+
<% end %>
|
16
|
+
<div class='description'>
|
17
|
+
<p><%= @content %></p>
|
18
|
+
</div>
|
19
|
+
</td>
|
20
|
+
</tr>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
23
|
+
</div>
|
data/spec/tag_spec.rb
CHANGED
@@ -34,7 +34,6 @@ describe Shortcode::Tag do
|
|
34
34
|
|
35
35
|
before(:each) do
|
36
36
|
Shortcode.setup do |config|
|
37
|
-
config.template_parser = :erb
|
38
37
|
config.templates = {
|
39
38
|
from_string: '<p><%= @attributes[:string] %></p>'
|
40
39
|
}
|
@@ -42,7 +41,7 @@ describe Shortcode::Tag do
|
|
42
41
|
end
|
43
42
|
|
44
43
|
it "renders a template from a string" do
|
45
|
-
tag.render.
|
44
|
+
expect(tag.render).to eq('<p>batman</p>')
|
46
45
|
end
|
47
46
|
|
48
47
|
end
|
@@ -53,7 +52,6 @@ describe Shortcode::Tag do
|
|
53
52
|
|
54
53
|
before(:each) do
|
55
54
|
Shortcode.setup do |config|
|
56
|
-
config.template_parser = :erb
|
57
55
|
config.templates = {
|
58
56
|
from_string: '<p><%= @attributes[:string] %></p>'
|
59
57
|
}
|
@@ -7,46 +7,23 @@ describe "template parsers" do
|
|
7
7
|
|
8
8
|
context "erb" do
|
9
9
|
|
10
|
-
# TODO remove this before block as erb will eb the default at version 0.4
|
11
|
-
before(:each) do
|
12
|
-
Shortcode.setup do |config|
|
13
|
-
config.template_parser = :erb
|
14
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
10
|
it "can render a template" do
|
19
|
-
Shortcode.process(simple_quote).gsub("\n",'').
|
11
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
20
12
|
end
|
21
13
|
|
22
14
|
end
|
23
15
|
|
24
16
|
context "haml" do
|
25
17
|
|
26
|
-
|
27
|
-
Shortcode.
|
28
|
-
|
29
|
-
|
30
|
-
context "when specified in the config" do
|
31
|
-
|
32
|
-
before(:each) do
|
33
|
-
Shortcode.setup do |config|
|
34
|
-
config.template_parser = :haml
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not show a deprecation warning" do
|
39
|
-
expect { Shortcode.process(simple_quote) }.not_to write(Shortcode.configuration.haml_deprecation_warning).to(:error)
|
18
|
+
before(:each) do
|
19
|
+
Shortcode.setup do |config|
|
20
|
+
config.template_parser = :haml
|
21
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
40
22
|
end
|
41
|
-
|
42
23
|
end
|
43
24
|
|
44
|
-
|
45
|
-
|
46
|
-
it "shows a deprecation warning" do
|
47
|
-
expect { Shortcode.process(simple_quote) }.to write(Shortcode.configuration.haml_deprecation_warning).to(:error)
|
48
|
-
end
|
49
|
-
|
25
|
+
it "can render a template" do
|
26
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
50
27
|
end
|
51
28
|
|
52
29
|
end
|
@@ -61,7 +38,7 @@ describe "template parsers" do
|
|
61
38
|
end
|
62
39
|
|
63
40
|
it "can render a template" do
|
64
|
-
Shortcode.process(simple_quote).gsub("\n",'').
|
41
|
+
expect(Shortcode.process(simple_quote).gsub("\n",'')).to eq(simple_quote_output)
|
65
42
|
end
|
66
43
|
|
67
44
|
end
|
data/spec/transformer_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe Shortcode do
|
|
34
34
|
it "converts into html" do
|
35
35
|
obj = parser.parse(simple_quote)
|
36
36
|
html = transformer.apply obj, additional_attributes: nil
|
37
|
-
html.
|
37
|
+
expect(html.gsub("\n", '')).to eq(simple_quote_output)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -43,7 +43,7 @@ describe Shortcode do
|
|
43
43
|
|
44
44
|
it "converts into html" do
|
45
45
|
html = transformer.apply(parser.parse(full_quote), additional_attributes: nil)
|
46
|
-
html.
|
46
|
+
expect(html.gsub("\n", '')).to eq(full_quote_output)
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -52,7 +52,7 @@ describe Shortcode do
|
|
52
52
|
|
53
53
|
it "converts into html" do
|
54
54
|
html = transformer.apply(parser.parse(quote_with_extras), additional_attributes: nil)
|
55
|
-
html.
|
55
|
+
expect(html.gsub("\n", '')).to eq(quote_with_extras_output)
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -61,7 +61,7 @@ describe Shortcode do
|
|
61
61
|
|
62
62
|
it "converts into html" do
|
63
63
|
html = transformer.apply(parser.parse(simple_list), additional_attributes: nil)
|
64
|
-
html.
|
64
|
+
expect(html.gsub("\n", '')).to eq(simple_list_output)
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -70,7 +70,7 @@ describe Shortcode do
|
|
70
70
|
|
71
71
|
it "converts into html" do
|
72
72
|
html = transformer.apply(parser.parse(timeline_event), additional_attributes: nil)
|
73
|
-
html.
|
73
|
+
expect(html.gsub("\n", '')).to eq(timeline_event_output)
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -79,7 +79,7 @@ describe Shortcode do
|
|
79
79
|
|
80
80
|
it "converts into html" do
|
81
81
|
html = transformer.apply(parser.parse(timeline_info), additional_attributes: nil)
|
82
|
-
html.
|
82
|
+
expect(html.gsub("\n", '')).to eq(timeline_info_output)
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
@@ -88,7 +88,7 @@ describe Shortcode do
|
|
88
88
|
|
89
89
|
it "converts into html" do
|
90
90
|
html = transformer.apply(parser.parse(timeline_person), additional_attributes: nil)
|
91
|
-
html.
|
91
|
+
expect(html.gsub("\n", '')).to eq(timeline_person_output)
|
92
92
|
end
|
93
93
|
|
94
94
|
end
|
@@ -97,22 +97,15 @@ describe Shortcode do
|
|
97
97
|
|
98
98
|
it "converts into html" do
|
99
99
|
html = transformer.apply(parser.parse(complex_snippet), additional_attributes: nil)
|
100
|
-
html.
|
100
|
+
expect(html.gsub("\n", '')).to eq(complex_snippet_output)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
context "erb templates" do
|
105
105
|
|
106
|
-
before(:each) do
|
107
|
-
Shortcode.setup do |config|
|
108
|
-
config.template_parser = :erb
|
109
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
106
|
it "converts into html" do
|
114
107
|
html = transformer.apply(parser.parse(simple_quote), additional_attributes: nil)
|
115
|
-
html.gsub("\n",'').
|
108
|
+
expect(html.gsub("\n",'')).to eq(simple_quote_output)
|
116
109
|
end
|
117
110
|
end
|
118
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shortcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.6.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: haml
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '4.0'
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '4.0'
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: bundler
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,17 +64,17 @@ dependencies:
|
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
81
65
|
none: false
|
82
66
|
requirements:
|
83
|
-
- -
|
67
|
+
- - ~>
|
84
68
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
69
|
+
version: 3.0.0
|
86
70
|
type: :development
|
87
71
|
prerelease: false
|
88
72
|
version_requirements: !ruby/object:Gem::Requirement
|
89
73
|
none: false
|
90
74
|
requirements:
|
91
|
-
- -
|
75
|
+
- - ~>
|
92
76
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
77
|
+
version: 3.0.0
|
94
78
|
- !ruby/object:Gem::Dependency
|
95
79
|
name: coveralls
|
96
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +107,22 @@ dependencies:
|
|
123
107
|
- - ~>
|
124
108
|
- !ruby/object:Gem::Version
|
125
109
|
version: '2.0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: haml
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '4.0'
|
126
126
|
description: Gem for parsing wordpress style shortcodes
|
127
127
|
email:
|
128
128
|
- jamie@kernowsoul.com
|
@@ -161,7 +161,6 @@ files:
|
|
161
161
|
- spec/rails_helpers_spec.rb
|
162
162
|
- spec/shortcode_spec.rb
|
163
163
|
- spec/spec_helper.rb
|
164
|
-
- spec/support/custom_expectations/write_expectation.rb
|
165
164
|
- spec/support/fixtures.rb
|
166
165
|
- spec/support/fixtures/complex_snippet.txt
|
167
166
|
- spec/support/fixtures/complex_snippet_output.html
|
@@ -186,15 +185,15 @@ files:
|
|
186
185
|
- spec/support/fixtures/timeline_info_output.html
|
187
186
|
- spec/support/fixtures/timeline_person.txt
|
188
187
|
- spec/support/fixtures/timeline_person_output.html
|
188
|
+
- spec/support/templates/erb/collapsible_list.html.erb
|
189
|
+
- spec/support/templates/erb/item.html.erb
|
189
190
|
- spec/support/templates/erb/quote.html.erb
|
190
191
|
- spec/support/templates/erb/rails_helper.html.erb
|
191
|
-
- spec/support/templates/
|
192
|
-
- spec/support/templates/
|
192
|
+
- spec/support/templates/erb/timeline_event.html.erb
|
193
|
+
- spec/support/templates/erb/timeline_info.html.erb
|
194
|
+
- spec/support/templates/erb/timeline_person.html.erb
|
193
195
|
- spec/support/templates/haml/quote.html.haml
|
194
196
|
- spec/support/templates/haml/rails_helper.html.haml
|
195
|
-
- spec/support/templates/haml/timeline_event.html.haml
|
196
|
-
- spec/support/templates/haml/timeline_info.html.haml
|
197
|
-
- spec/support/templates/haml/timeline_person.html.haml
|
198
197
|
- spec/support/templates/slim/quote.html.slim
|
199
198
|
- spec/support/templates/slim/rails_helper.html.slim
|
200
199
|
- spec/tag_spec.rb
|
@@ -232,7 +231,6 @@ test_files:
|
|
232
231
|
- spec/rails_helpers_spec.rb
|
233
232
|
- spec/shortcode_spec.rb
|
234
233
|
- spec/spec_helper.rb
|
235
|
-
- spec/support/custom_expectations/write_expectation.rb
|
236
234
|
- spec/support/fixtures.rb
|
237
235
|
- spec/support/fixtures/complex_snippet.txt
|
238
236
|
- spec/support/fixtures/complex_snippet_output.html
|
@@ -257,15 +255,15 @@ test_files:
|
|
257
255
|
- spec/support/fixtures/timeline_info_output.html
|
258
256
|
- spec/support/fixtures/timeline_person.txt
|
259
257
|
- spec/support/fixtures/timeline_person_output.html
|
258
|
+
- spec/support/templates/erb/collapsible_list.html.erb
|
259
|
+
- spec/support/templates/erb/item.html.erb
|
260
260
|
- spec/support/templates/erb/quote.html.erb
|
261
261
|
- spec/support/templates/erb/rails_helper.html.erb
|
262
|
-
- spec/support/templates/
|
263
|
-
- spec/support/templates/
|
262
|
+
- spec/support/templates/erb/timeline_event.html.erb
|
263
|
+
- spec/support/templates/erb/timeline_info.html.erb
|
264
|
+
- spec/support/templates/erb/timeline_person.html.erb
|
264
265
|
- spec/support/templates/haml/quote.html.haml
|
265
266
|
- spec/support/templates/haml/rails_helper.html.haml
|
266
|
-
- spec/support/templates/haml/timeline_event.html.haml
|
267
|
-
- spec/support/templates/haml/timeline_info.html.haml
|
268
|
-
- spec/support/templates/haml/timeline_person.html.haml
|
269
267
|
- spec/support/templates/slim/quote.html.slim
|
270
268
|
- spec/support/templates/slim/rails_helper.html.slim
|
271
269
|
- spec/tag_spec.rb
|
@@ -1,62 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :write do |message|
|
2
|
-
|
3
|
-
chain(:to) do |io|
|
4
|
-
@io = io
|
5
|
-
end
|
6
|
-
|
7
|
-
match do |block|
|
8
|
-
output =
|
9
|
-
case io
|
10
|
-
when :output then fake_stdout(&block)
|
11
|
-
when :error then fake_stderr(&block)
|
12
|
-
else raise("Allowed values for `to` are :output and :error, got `#{io.inspect}`")
|
13
|
-
end
|
14
|
-
output.include? message
|
15
|
-
end
|
16
|
-
|
17
|
-
description do
|
18
|
-
"write \"#{message}\" #{io_name}"
|
19
|
-
end
|
20
|
-
|
21
|
-
failure_message_for_should do
|
22
|
-
"expected to #{description}"
|
23
|
-
end
|
24
|
-
|
25
|
-
failure_message_for_should_not do
|
26
|
-
"expected to not #{description}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def supports_block_expectations?
|
30
|
-
true
|
31
|
-
end
|
32
|
-
|
33
|
-
# Fake STDERR and return a string written to it.
|
34
|
-
def fake_stderr
|
35
|
-
original_stderr = $stderr
|
36
|
-
$stderr = StringIO.new
|
37
|
-
yield
|
38
|
-
$stderr.string
|
39
|
-
ensure
|
40
|
-
$stderr = original_stderr
|
41
|
-
end
|
42
|
-
|
43
|
-
# Fake STDOUT and return a string written to it.
|
44
|
-
def fake_stdout
|
45
|
-
original_stdout = $stdout
|
46
|
-
$stdout = StringIO.new
|
47
|
-
yield
|
48
|
-
$stdout.string
|
49
|
-
ensure
|
50
|
-
$stdout = original_stdout
|
51
|
-
end
|
52
|
-
|
53
|
-
# default IO is standard output
|
54
|
-
def io
|
55
|
-
@io ||= :output
|
56
|
-
end
|
57
|
-
|
58
|
-
# IO name is used for description message
|
59
|
-
def io_name
|
60
|
-
{ output: "standard output", error: "standard error" }[io]
|
61
|
-
end
|
62
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
.timeline
|
2
|
-
%table
|
3
|
-
%tbody
|
4
|
-
%tr
|
5
|
-
%th{scope: :row}
|
6
|
-
= @attributes[:date]
|
7
|
-
%td.team_news
|
8
|
-
%img{src: @attributes[:image]}
|
9
|
-
%h4= @attributes[:title]
|
10
|
-
%span.name= @attributes[:name]
|
11
|
-
%span.position= @attributes[:position]
|
12
|
-
-if @attributes[:link]
|
13
|
-
%a.read_more{href: @attributes[:link]} View Profile
|
14
|
-
.description
|
15
|
-
%p= @content
|