shortcode 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/shortcode/configuration.rb +14 -0
- data/lib/shortcode/tag.rb +1 -0
- data/lib/shortcode/version.rb +1 -1
- data/spec/rails_helpers_spec.rb +13 -12
- data/spec/spec_helper.rb +5 -0
- data/spec/support/custom_expectations/write_expectation.rb +62 -0
- data/spec/support/templates/slim/quote.html.slim +8 -0
- data/spec/template_parsers_spec.rb +69 -0
- metadata +8 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,20 @@
|
|
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
|
+
|
2
10
|
# Sets the template parser to use, supports :erb, :haml, and :slim, default is :haml
|
3
11
|
attr_accessor :template_parser
|
4
12
|
|
13
|
+
def template_parser=(parser)
|
14
|
+
@parser_set = true
|
15
|
+
@template_parser = parser
|
16
|
+
end
|
17
|
+
|
5
18
|
# Sets the path to search for template files
|
6
19
|
attr_accessor :template_path
|
7
20
|
|
@@ -24,5 +37,6 @@ class Shortcode::Configuration
|
|
24
37
|
@block_tags = []
|
25
38
|
@self_closing_tags = []
|
26
39
|
@quotes = '"'
|
40
|
+
@parser_set = false
|
27
41
|
end
|
28
42
|
end
|
data/lib/shortcode/tag.rb
CHANGED
@@ -32,6 +32,7 @@ class Shortcode::Tag
|
|
32
32
|
when :slim
|
33
33
|
Slim::Template.new { markup }.render(self)
|
34
34
|
when :haml
|
35
|
+
warn Shortcode.configuration.haml_deprecation_warning unless Shortcode.configuration.parser_set
|
35
36
|
Haml::Engine.new(markup, ugly: true).render(binding)
|
36
37
|
when :erb
|
37
38
|
ERB.new(markup).result(binding)
|
data/lib/shortcode/version.rb
CHANGED
data/spec/rails_helpers_spec.rb
CHANGED
@@ -3,21 +3,22 @@ require 'spec_helper'
|
|
3
3
|
describe "rails helpers" do
|
4
4
|
|
5
5
|
let(:template) { load_fixture :rails_helper }
|
6
|
-
|
6
|
+
|
7
|
+
let(:erb_output) { load_fixture :rails_helper_output_erb, :html }
|
7
8
|
let(:haml_output) { load_fixture :rails_helper_output_haml, :html }
|
8
|
-
let(:
|
9
|
+
let(:slim_output) { load_fixture :rails_helper_output_slim, :html }
|
9
10
|
|
10
|
-
describe "
|
11
|
+
describe "erb" do
|
11
12
|
|
12
13
|
before(:each) do
|
13
14
|
Shortcode.setup do |config|
|
14
|
-
config.template_parser = :
|
15
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/
|
15
|
+
config.template_parser = :erb
|
16
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
it "are accessible within
|
20
|
-
Shortcode.process(template).gsub("\n",'').should ==
|
20
|
+
it "are accessible within erb templates" do
|
21
|
+
Shortcode.process(template).gsub("\n",'').should == erb_output.gsub("\n",'')
|
21
22
|
end
|
22
23
|
|
23
24
|
end
|
@@ -30,17 +31,17 @@ describe "rails helpers" do
|
|
30
31
|
|
31
32
|
end
|
32
33
|
|
33
|
-
describe "
|
34
|
+
describe "slim" do
|
34
35
|
|
35
36
|
before(:each) do
|
36
37
|
Shortcode.setup do |config|
|
37
|
-
config.template_parser = :
|
38
|
-
config.template_path = File.join File.dirname(__FILE__), "support/templates/
|
38
|
+
config.template_parser = :slim
|
39
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/slim"
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
it "are accessible within
|
43
|
-
Shortcode.process(template).gsub("\n",'').should ==
|
43
|
+
it "are accessible within slim templates" do
|
44
|
+
Shortcode.process(template).gsub("\n",'').should == slim_output.gsub("\n",'')
|
44
45
|
end
|
45
46
|
|
46
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,10 @@ require 'rails'
|
|
8
8
|
require 'action_view'
|
9
9
|
require 'shortcode'
|
10
10
|
require 'support/fixtures'
|
11
|
+
require 'support/custom_expectations/write_expectation'
|
12
|
+
|
13
|
+
# Set slim's attribute quotes to use single quotes so it's the same as haml
|
14
|
+
Slim::Engine.set_default_options attr_quote: "'"
|
11
15
|
|
12
16
|
RSpec.configure do |config|
|
13
17
|
config.order = "random"
|
@@ -16,6 +20,7 @@ RSpec.configure do |config|
|
|
16
20
|
Shortcode.presenters = {}
|
17
21
|
Shortcode.setup do |config|
|
18
22
|
config.template_parser = :haml
|
23
|
+
config.parser_set = false
|
19
24
|
config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
|
20
25
|
config.templates = nil
|
21
26
|
config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper]
|
@@ -0,0 +1,62 @@
|
|
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
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "template parsers" do
|
4
|
+
|
5
|
+
let(:simple_quote) { load_fixture :simple_quote }
|
6
|
+
let(:simple_quote_output) { load_fixture :simple_quote_output, :html }
|
7
|
+
|
8
|
+
context "erb" do
|
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
|
+
it "can render a template" do
|
19
|
+
Shortcode.process(simple_quote).gsub("\n",'').should == simple_quote_output.gsub("\n",'')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "haml" do
|
25
|
+
|
26
|
+
it "can render a template" do
|
27
|
+
Shortcode.process(simple_quote).gsub("\n",'').should == simple_quote_output.gsub("\n",'')
|
28
|
+
end
|
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)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when not specifed in the config" do
|
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
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "slim" do
|
55
|
+
|
56
|
+
before(:each) do
|
57
|
+
Shortcode.setup do |config|
|
58
|
+
config.template_parser = :slim
|
59
|
+
config.template_path = File.join File.dirname(__FILE__), "support/templates/slim"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can render a template" do
|
64
|
+
Shortcode.process(simple_quote).gsub("\n",'').should == simple_quote_output.gsub("\n",'')
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
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.3.
|
4
|
+
version: 0.3.3
|
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-
|
12
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -161,6 +161,7 @@ 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
|
164
165
|
- spec/support/fixtures.rb
|
165
166
|
- spec/support/fixtures/complex_snippet.txt
|
166
167
|
- spec/support/fixtures/complex_snippet_output.html
|
@@ -194,8 +195,10 @@ files:
|
|
194
195
|
- spec/support/templates/haml/timeline_event.html.haml
|
195
196
|
- spec/support/templates/haml/timeline_info.html.haml
|
196
197
|
- spec/support/templates/haml/timeline_person.html.haml
|
198
|
+
- spec/support/templates/slim/quote.html.slim
|
197
199
|
- spec/support/templates/slim/rails_helper.html.slim
|
198
200
|
- spec/tag_spec.rb
|
201
|
+
- spec/template_parsers_spec.rb
|
199
202
|
- spec/transformer_spec.rb
|
200
203
|
homepage: https://github.com/kernow/shortcode
|
201
204
|
licenses:
|
@@ -229,6 +232,7 @@ test_files:
|
|
229
232
|
- spec/rails_helpers_spec.rb
|
230
233
|
- spec/shortcode_spec.rb
|
231
234
|
- spec/spec_helper.rb
|
235
|
+
- spec/support/custom_expectations/write_expectation.rb
|
232
236
|
- spec/support/fixtures.rb
|
233
237
|
- spec/support/fixtures/complex_snippet.txt
|
234
238
|
- spec/support/fixtures/complex_snippet_output.html
|
@@ -262,6 +266,8 @@ test_files:
|
|
262
266
|
- spec/support/templates/haml/timeline_event.html.haml
|
263
267
|
- spec/support/templates/haml/timeline_info.html.haml
|
264
268
|
- spec/support/templates/haml/timeline_person.html.haml
|
269
|
+
- spec/support/templates/slim/quote.html.slim
|
265
270
|
- spec/support/templates/slim/rails_helper.html.slim
|
266
271
|
- spec/tag_spec.rb
|
272
|
+
- spec/template_parsers_spec.rb
|
267
273
|
- spec/transformer_spec.rb
|