shortcode 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals CHANGED
@@ -7,13 +7,13 @@ appraise "rails-3.1" do
7
7
  end
8
8
 
9
9
  appraise "rails-3.2" do
10
- gem "rails", "~> 3.2.18"
10
+ gem "rails", "~> 3.2.19"
11
11
  end
12
12
 
13
13
  appraise "rails-4.0" do
14
- gem "rails", "~> 4.0.5"
14
+ gem "rails", "~> 4.0.8"
15
15
  end
16
16
 
17
17
  appraise "rails-4.1" do
18
- gem "rails", "~> 4.1.1"
18
+ gem "rails", "~> 4.1.4"
19
19
  end
data/CHANGELOG.md ADDED
@@ -0,0 +1,123 @@
1
+ ## 0.4.3 (July 16, 2014)
2
+
3
+ Features:
4
+
5
+ - Adds support for custom helpers in templates
6
+
7
+
8
+ ## 0.4.2 (July 1, 2014)
9
+
10
+ Features:
11
+
12
+ - Adds presenter class method validation
13
+
14
+
15
+ ## 0.4.1 (June 18, 2014)
16
+
17
+ Features:
18
+
19
+ - Adds support to apply a single presenter to multiple short code snippets
20
+
21
+ Misc:
22
+
23
+ - Prevent coveralls from running locally
24
+ - Updated to rspec 3
25
+
26
+
27
+ ## 0.4.0 (June 16, 2014)
28
+
29
+ Features:
30
+
31
+ - Switched to erb as the default template language and removed dependency on haml
32
+
33
+
34
+ ## 0.3.3 (June 3, 2014)
35
+
36
+ Misc:
37
+
38
+ - Added haml default template parser deprecation message
39
+
40
+
41
+ ## 0.3.1 (May 30, 2014)
42
+
43
+ Features:
44
+
45
+ - Added support for slim templates (@keichan34)
46
+ - Updated rails versions to test against and updated read me with tested versions of ruby/rails
47
+
48
+
49
+ ## 0.3.0 (May 13, 2014)
50
+
51
+ Features:
52
+
53
+ - Added config option to support loading templates from strings
54
+
55
+
56
+ ## 0.2.0 (May 9, 2014)
57
+
58
+ Features:
59
+
60
+ - Presenters now support additional attributes
61
+ - Updated parslet gem to 1.6.0 for performance improvements
62
+ - Add config option for quotation sign (@lenart)
63
+
64
+
65
+ ## 0.1.2 (March 18, 2014)
66
+
67
+ Features:
68
+
69
+ - Test suite runs against multiple version of ruby and rails
70
+
71
+ Bugfixes:
72
+
73
+ - Presenters are now initialised correctly, allow gem to be used without needing to call Shortcode.setup (fixes #6)
74
+ - Only include rails helpers in rails version 3 or higher
75
+
76
+ Misc:
77
+
78
+ - Simplify presenter image lookup in README (@chrsgrrtt)
79
+
80
+
81
+ ## 0.1.1 (February 23, 2014)
82
+
83
+ Features:
84
+
85
+ - Support rails helpers in templates when used within a rails project
86
+
87
+
88
+ ## 0.1.0 (February 23, 2014)
89
+
90
+ Features:
91
+
92
+ - Presenters added
93
+
94
+
95
+ ## 0.0.4 (February 23, 2014)
96
+
97
+ Bugfixes:
98
+
99
+ - Support configurations with empty tag arrays (fixes #1)
100
+
101
+
102
+ ## 0.0.3 (August 23, 2013)
103
+
104
+ Misc:
105
+
106
+ - Relaxed haml version requirement
107
+ - Removed dependency on the facets gem
108
+
109
+
110
+ ## 0.0.2 (August 7, 2013)
111
+
112
+ Features:
113
+
114
+ - Added a convenience method to parse and transform at the same time
115
+ - Added examples to README
116
+ - Changed default tags in config
117
+ - Changed @options variable to @attributes in templates to better describe what it is
118
+ - Change the @text variable to @content in templates
119
+
120
+
121
+ ## 0.0.1 (August 5, 2013)
122
+
123
+ Initial Release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shortcode (0.4.2)
4
+ shortcode (0.4.3)
5
5
  parslet (= 1.6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Shortcode
2
2
 
3
- A ruby gem for parsing Wordpress style shortcodes. The gem uses a [PEG](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (Parsing Expression Grammar) parser rather than using regular expressions so its easier to understand, test and extend.
3
+ Shortcode is a ruby gem for parsing Wordpress style shortcodes, I created it while building a CMS for a client through [my ruby consultancy, Kernow Soul](http://kernowsoul.com). The gem uses a [PEG](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (Parsing Expression Grammar) parser rather than using regular expressions so its easier to understand, test and extend.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/shortcode.svg)](http://badge.fury.io/rb/shortcode)
6
6
  [![Build Status](https://travis-ci.org/kernow/shortcode.png?branch=master)](https://travis-ci.org/kernow/shortcode)
@@ -40,32 +40,6 @@ Shortcode is very simple to use, simply call the `process` method and pass it a
40
40
  Shortcode.process("[quote]Hello World[/quote]")
41
41
  ```
42
42
 
43
- ### Configuration
44
-
45
- ```ruby
46
- Shortcode.setup do |config|
47
-
48
- # the template parser to use
49
- config.template_parser = :erb # :erb, :haml, :slim supported, :erb is default
50
-
51
- # location of the template files, default is "app/views/shortcode_templates"
52
- config.template_path = "support/templates/erb"
53
-
54
- # a hash of templates passed as strings, if this is set it overrides the
55
- # above template_path option. The default is nil
56
- config.templates = { gallery: 'template code' }
57
-
58
- # a list of block tags to support e.g. [quote]Hello World[/quote]
59
- config.block_tags = [:quote]
60
-
61
- # a list of self closing tags to support e.g. [youtube id="12345"]
62
- config.self_closing_tags = [:youtube]
63
-
64
- # the type of quotes to use for attribute values, default is double quotes (")
65
- config.quotes = '"'
66
- end
67
- ```
68
-
69
43
  ### Templates
70
44
 
71
45
  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
@@ -125,6 +99,15 @@ end
125
99
  If the `templates` config option is set all templates will be loaded from this hash, if a shortcode is encountered without a matching key in the `templates` config option
126
100
  an exception will be raised.
127
101
 
102
+ ### Custom Helpers
103
+
104
+ If you wish to use custom helper modules in templates you can do so by specifying the helpers in a setup block which should be an array. Methods in the helper modules will then become available within all tempaltes.
105
+
106
+ ```ruby
107
+ Shortcode.setup do |config|
108
+ config.helpers = [CustomHelper, AnotherCustomHelper]
109
+ end
110
+
128
111
  ### Presenters
129
112
 
130
113
  Sometimes the data passed to the template from the shortcode it not enough. Lets say you want to render a gallery of images using id numbers of images stored in a database, e.g. `[gallery ids="1,2,3,4"]`. This is where presenters can help, they allow you to modify the `@content` and `@attributes` variables before they are sent to the template for rendering. Presenters are simple classes that define four methods. The class method `for` should return the name of the shortcode (as a symbol) it should be applied to, the `for` method can also return an array of symbols if the presenter is to be used for multiple shortcodes. The classes `initialize` method received the `attributes`, `content` and `additional_attributes` variables. Finally the class should define `content` and `attributes` methods.
@@ -205,6 +188,36 @@ To register a presenter simply call `Shortcode.register_presenter` passing the p
205
188
  Shortcode.register_presenter(CustomPresenter)
206
189
  ```
207
190
 
191
+ ### Configuration
192
+
193
+ ```ruby
194
+ Shortcode.setup do |config|
195
+
196
+ # the template parser to use
197
+ config.template_parser = :erb # :erb, :haml, :slim supported, :erb is default
198
+
199
+ # location of the template files, default is "app/views/shortcode_templates"
200
+ config.template_path = "support/templates/erb"
201
+
202
+ # a hash of templates passed as strings, if this is set it overrides the
203
+ # above template_path option. The default is nil
204
+ config.templates = { gallery: 'template code' }
205
+
206
+ # an array of helper modules to make available within tempaltes
207
+ config.helpers = [CustomerHelper]
208
+
209
+ # a list of block tags to support e.g. [quote]Hello World[/quote]
210
+ config.block_tags = [:quote]
211
+
212
+ # a list of self closing tags to support e.g. [youtube id="12345"]
213
+ config.self_closing_tags = [:youtube]
214
+
215
+ # the type of quotes to use for attribute values, default is double quotes (")
216
+ config.quotes = '"'
217
+ end
218
+ ```
219
+
220
+
208
221
  ## Contributing
209
222
 
210
223
  1. Fork it
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal", "1.0.0.beta3"
6
- gem "rails", "~> 3.2.18"
6
+ gem "rails", "~> 3.2.19"
7
7
 
8
8
  gemspec :path=>".././"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal", "1.0.0.beta3"
6
- gem "rails", "~> 4.0.5"
6
+ gem "rails", "~> 4.0.8"
7
7
 
8
8
  gemspec :path=>".././"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal", "1.0.0.beta3"
6
- gem "rails", "~> 4.1.1"
6
+ gem "rails", "~> 4.1.4"
7
7
 
8
8
  gemspec :path=>".././"
@@ -8,6 +8,9 @@ class Shortcode::Configuration
8
8
  # Allows templates to be set from strings rather than read from the filesystem
9
9
  attr_accessor :templates
10
10
 
11
+ # Assigns helper modules to be included in templates
12
+ attr_accessor :helpers
13
+
11
14
  # Set the supported block_tags
12
15
  attr_accessor :block_tags
13
16
 
@@ -21,6 +24,7 @@ class Shortcode::Configuration
21
24
  @template_parser = :erb
22
25
  @template_path = "app/views/shortcode_templates"
23
26
  @templates = nil
27
+ @helpers = []
24
28
  @block_tags = []
25
29
  @self_closing_tags = []
26
30
  @quotes = '"'
data/lib/shortcode/tag.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class Shortcode::Tag
2
2
 
3
3
  def initialize(name, attributes=[], content='', additional_attributes=nil)
4
+ include_helper_modules
4
5
  @name = name.downcase
5
6
  presenter = Shortcode::Presenter.new name, set_attributes(attributes), content, additional_attributes
6
7
  @attributes = presenter.attributes
@@ -27,6 +28,15 @@ class Shortcode::Tag
27
28
 
28
29
  private
29
30
 
31
+ def include_helper_modules
32
+ return unless Shortcode.configuration.helpers.any?
33
+ class << self
34
+ Shortcode.configuration.helpers.each do |helper|
35
+ include helper
36
+ end
37
+ end
38
+ end
39
+
30
40
  def render_template
31
41
  case Shortcode.configuration.template_parser
32
42
  when :erb
@@ -1,3 +1,3 @@
1
1
  module Shortcode
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -1,5 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module ShortcodeSpecViewHelper
4
+ def wrap_in_p(content)
5
+ content_tag :p, content
6
+ end
7
+ end
8
+
3
9
  describe "rails helpers" do
4
10
 
5
11
  let(:template) { load_fixture :rails_helper }
@@ -46,4 +52,21 @@ describe "rails helpers" do
46
52
 
47
53
  end
48
54
 
55
+ describe "using a custom helper module" do
56
+
57
+ let(:template) { load_fixture :custom_helper }
58
+ let(:output) { load_fixture :custom_helper_output, :html }
59
+
60
+ before(:each) do
61
+ Shortcode.setup do |config|
62
+ config.helpers = [ShortcodeSpecViewHelper]
63
+ end
64
+ end
65
+
66
+ it "is accessible within templates" do
67
+ expect(Shortcode.process(template).gsub("\n",'')).to eq(output)
68
+ end
69
+
70
+ end
71
+
49
72
  end
data/spec/spec_helper.rb CHANGED
@@ -23,7 +23,7 @@ RSpec.configure do |config|
23
23
  config.template_parser = :erb
24
24
  config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
25
25
  config.templates = nil
26
- config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper]
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
28
  config.quotes = '"'
29
29
  end
@@ -0,0 +1 @@
1
+ [custom_helper]something[/custom_helper]
@@ -0,0 +1 @@
1
+ <p>something</p>
@@ -0,0 +1 @@
1
+ <%= wrap_in_p(@content) %>
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.2
4
+ version: 0.4.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-07-01 00:00:00.000000000 Z
12
+ date: 2014-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -134,6 +134,7 @@ files:
134
134
  - .rbenv-version
135
135
  - .travis.yml
136
136
  - Appraisals
137
+ - CHANGELOG.md
137
138
  - Gemfile
138
139
  - Gemfile.lock
139
140
  - LICENSE.txt
@@ -164,6 +165,8 @@ files:
164
165
  - spec/support/fixtures.rb
165
166
  - spec/support/fixtures/complex_snippet.txt
166
167
  - spec/support/fixtures/complex_snippet_output.html
168
+ - spec/support/fixtures/custom_helper.txt
169
+ - spec/support/fixtures/custom_helper_output.html
167
170
  - spec/support/fixtures/full_quote.txt
168
171
  - spec/support/fixtures/full_quote_output.html
169
172
  - spec/support/fixtures/item.txt
@@ -195,6 +198,7 @@ files:
195
198
  - spec/support/presenters/multiple_presenter.rb
196
199
  - spec/support/presenters/my_presenter.rb
197
200
  - spec/support/templates/erb/collapsible_list.html.erb
201
+ - spec/support/templates/erb/custom_helper.html.erb
198
202
  - spec/support/templates/erb/item.html.erb
199
203
  - spec/support/templates/erb/quote.html.erb
200
204
  - spec/support/templates/erb/rails_helper.html.erb
@@ -243,6 +247,8 @@ test_files:
243
247
  - spec/support/fixtures.rb
244
248
  - spec/support/fixtures/complex_snippet.txt
245
249
  - spec/support/fixtures/complex_snippet_output.html
250
+ - spec/support/fixtures/custom_helper.txt
251
+ - spec/support/fixtures/custom_helper_output.html
246
252
  - spec/support/fixtures/full_quote.txt
247
253
  - spec/support/fixtures/full_quote_output.html
248
254
  - spec/support/fixtures/item.txt
@@ -274,6 +280,7 @@ test_files:
274
280
  - spec/support/presenters/multiple_presenter.rb
275
281
  - spec/support/presenters/my_presenter.rb
276
282
  - spec/support/templates/erb/collapsible_list.html.erb
283
+ - spec/support/templates/erb/custom_helper.html.erb
277
284
  - spec/support/templates/erb/item.html.erb
278
285
  - spec/support/templates/erb/quote.html.erb
279
286
  - spec/support/templates/erb/rails_helper.html.erb