shortcode 0.4.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ ## 1.0.0 (July 29, 2014)
2
+
3
+ Features:
4
+
5
+ - Adds support for attributes without quotations around them
6
+
7
+ Breaking Changes:
8
+
9
+ - Renamed configuration options so they are more clear
10
+
11
+
1
12
  ## 0.4.3 (July 16, 2014)
2
13
 
3
14
  Features:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shortcode (0.4.3)
4
+ shortcode (1.0.0)
5
5
  parslet (= 1.6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -107,6 +107,7 @@ If you wish to use custom helper modules in templates you can do so by specifyin
107
107
  Shortcode.setup do |config|
108
108
  config.helpers = [CustomHelper, AnotherCustomHelper]
109
109
  end
110
+ ```
110
111
 
111
112
  ### Presenters
112
113
 
@@ -213,7 +214,10 @@ Shortcode.setup do |config|
213
214
  config.self_closing_tags = [:youtube]
214
215
 
215
216
  # the type of quotes to use for attribute values, default is double quotes (")
216
- config.quotes = '"'
217
+ config.attribute_quote_type = '"'
218
+
219
+ # Allows quotes around attributes to be omitted. Defaults to true (quotes must be present around the value).
220
+ config.use_attribute_quotes = true
217
221
  end
218
222
  ```
219
223
 
@@ -18,15 +18,19 @@ class Shortcode::Configuration
18
18
  attr_accessor :self_closing_tags
19
19
 
20
20
  # Set the quotation sign used for attribute values. Defaults to double quote (")
21
- attr_accessor :quotes
21
+ attr_accessor :attribute_quote_type
22
+
23
+ # Allows quotes around attributes to be omitted. Defaults to false (quotes must be present around the value).
24
+ attr_accessor :use_attribute_quotes
22
25
 
23
26
  def initialize
24
- @template_parser = :erb
25
- @template_path = "app/views/shortcode_templates"
26
- @templates = nil
27
- @helpers = []
28
- @block_tags = []
29
- @self_closing_tags = []
30
- @quotes = '"'
27
+ @template_parser = :erb
28
+ @template_path = "app/views/shortcode_templates"
29
+ @templates = nil
30
+ @helpers = []
31
+ @block_tags = []
32
+ @self_closing_tags = []
33
+ @attribute_quote_type = '"'
34
+ @use_attribute_quotes = true
31
35
  end
32
36
  end
@@ -3,7 +3,7 @@ class Shortcode::Parser < Parslet::Parser
3
3
  rule(:block_tag) { match_any_of Shortcode.configuration.block_tags }
4
4
  rule(:self_closing_tag) { match_any_of Shortcode.configuration.self_closing_tags }
5
5
 
6
- rule(:quotes) { str(Shortcode.configuration.quotes) }
6
+ rule(:quotes) { str(Shortcode.configuration.attribute_quote_type) }
7
7
 
8
8
  rule(:space) { str(' ').repeat(1) }
9
9
  rule(:space?) { space.maybe }
@@ -11,8 +11,11 @@ class Shortcode::Parser < Parslet::Parser
11
11
  rule(:whitespace) { (space | newline).repeat(1) }
12
12
  rule(:whitespace?) { whitespace.maybe }
13
13
 
14
- rule(:key) { match('[a-zA-Z0-9\-_]').repeat(1) }
15
- rule(:value) { quotes >> (quotes.absent? >> any).repeat.as(:value) >> quotes }
14
+ rule(:key) { match('[a-zA-Z0-9\-_]').repeat(1) }
15
+
16
+ rule(:value_with_quotes) { quotes >> (quotes.absent? >> any).repeat.as(:value) >> quotes }
17
+ rule(:value_without_quotes) { quotes.absent? >> ( (str(']') | whitespace).absent? >> any ).repeat.as(:value) }
18
+ rule(:value) { Shortcode.configuration.use_attribute_quotes ? value_with_quotes : (value_without_quotes | value_with_quotes) }
16
19
 
17
20
  rule(:option) { key.as(:key) >> str('=') >> value }
18
21
  rule(:options) { (str(' ') >> option).repeat(1) }
@@ -1,3 +1,3 @@
1
1
  module Shortcode
2
- VERSION = "0.4.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -8,6 +8,7 @@ describe Shortcode::Parser do
8
8
 
9
9
  let(:simple_quote) { load_fixture :simple_quote }
10
10
  let(:full_quote) { load_fixture :full_quote }
11
+ let(:without_quotes) { load_fixture :without_quotes }
11
12
  let(:quote_with_extras) { load_fixture :quote_with_extras }
12
13
  let(:simple_list) { load_fixture :simple_list }
13
14
  let(:timeline_event) { load_fixture :timeline_event }
@@ -25,20 +26,35 @@ describe Shortcode::Parser do
25
26
  end
26
27
  end
27
28
 
28
- it "parses quotes using custom quotations" do
29
- Shortcode.setup do |config|
30
- config.quotes = "'"
29
+ context "attribute_quote_type configuration" do
30
+
31
+ before do
32
+ Shortcode.setup do |config|
33
+ config.attribute_quote_type = "'"
34
+ end
31
35
  end
32
36
 
33
- quotes.each do |string|
34
- # Change double quotes to single quotes in the fixture
35
- expect(parser).to parse(string.gsub '"', "'")
37
+ it "parses quotes using custom quotations" do
38
+ quotes.each do |string|
39
+ # Change double quotes to single quotes in the fixture
40
+ expect(parser).to parse(string.gsub '"', "'")
41
+ end
36
42
  end
37
43
 
38
- # Reset configuration to default
39
- Shortcode.setup do |config|
40
- config.quotes = '"'
44
+ end
45
+
46
+ context "use_attribute_quotes configuration" do
47
+
48
+ before do
49
+ Shortcode.setup do |config|
50
+ config.use_attribute_quotes = false
51
+ end
41
52
  end
53
+
54
+ it "parses shortcodes with optional quotes" do
55
+ expect(parser).to parse(without_quotes)
56
+ end
57
+
42
58
  end
43
59
 
44
60
  it "parses list shortcodes" do
@@ -25,7 +25,8 @@ RSpec.configure do |config|
25
25
  config.templates = nil
26
26
  config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper, :custom_helper]
27
27
  config.self_closing_tags = [:timeline_event, :timeline_info]
28
- config.quotes = '"'
28
+ config.attribute_quote_type = '"'
29
+ config.use_attribute_quotes = true
29
30
  end
30
31
  end
31
32
  end
@@ -0,0 +1 @@
1
+ [quote author="Jamie Dyer" title=King_of_England]A quote[/quote]
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.3
4
+ version: 1.0.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-07-16 00:00:00.000000000 Z
12
+ date: 2014-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -191,6 +191,7 @@ files:
191
191
  - spec/support/fixtures/timeline_info_output.html
192
192
  - spec/support/fixtures/timeline_person.txt
193
193
  - spec/support/fixtures/timeline_person_output.html
194
+ - spec/support/fixtures/without_quotes.txt
194
195
  - spec/support/presenters/missing_attributes_presenter.rb
195
196
  - spec/support/presenters/missing_content_presenter.rb
196
197
  - spec/support/presenters/missing_for_presenter.rb
@@ -273,6 +274,7 @@ test_files:
273
274
  - spec/support/fixtures/timeline_info_output.html
274
275
  - spec/support/fixtures/timeline_person.txt
275
276
  - spec/support/fixtures/timeline_person_output.html
277
+ - spec/support/fixtures/without_quotes.txt
276
278
  - spec/support/presenters/missing_attributes_presenter.rb
277
279
  - spec/support/presenters/missing_content_presenter.rb
278
280
  - spec/support/presenters/missing_for_presenter.rb