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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6e16afa9cbced683fa57993d25230c1ccbbc17d
|
4
|
+
data.tar.gz: 3085a76be15d7c3522219ff2efa39b2e5db9bf1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc17a4b44ad1e685609b44a735395ed8802a834810b9d36cb403ab671a05b34056ea2329cb63bcc4002e4107774f0747bbd66968ce66b1f8b3a62d104c14130e
|
7
|
+
data.tar.gz: 1e816940f82d9cede5b8741cb02591dc1fbe5a5b8d060f1cacd3cec152f6650d78b4c619b8134bcf7d075307d4d2b676428dc045b7a32aa23e09ce84685987e8
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.3
|
data/.travis.yml
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
4
|
+
- 2.2.7
|
5
|
+
- 2.3.4
|
6
|
+
- 2.4.1
|
7
7
|
- ruby-head
|
8
|
-
- jruby-
|
9
|
-
- jruby-head
|
8
|
+
- jruby-9.1.9.0
|
10
9
|
|
11
10
|
sudo: false
|
12
11
|
|
13
12
|
script: bundle exec rspec
|
14
13
|
|
15
14
|
before_install:
|
16
|
-
- gem install bundler -v 1.
|
15
|
+
- gem install bundler -v 1.15.0
|
17
16
|
|
18
17
|
matrix:
|
19
18
|
allow_failures:
|
20
19
|
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
22
20
|
|
23
21
|
gemfile:
|
24
|
-
- gemfiles/rails_3.2.gemfile
|
25
|
-
- gemfiles/rails_4.0.gemfile
|
26
22
|
- gemfiles/rails_4.1.gemfile
|
27
23
|
- gemfiles/rails_4.2.gemfile
|
24
|
+
- gemfiles/rails_5.0.gemfile
|
25
|
+
- gemfiles/rails_5.1.gemfile
|
data/Appraisals
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
appraise "rails-
|
2
|
-
gem "rails", "~>
|
1
|
+
appraise "rails-4.1" do
|
2
|
+
gem "rails", "~> 4.1.16"
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise "rails-4.
|
6
|
-
gem "rails", "
|
5
|
+
appraise "rails-4.2" do
|
6
|
+
gem "rails", "4.2.8"
|
7
7
|
end
|
8
8
|
|
9
|
-
appraise "rails-
|
10
|
-
gem "rails", "
|
9
|
+
appraise "rails-5.0" do
|
10
|
+
gem "rails", "5.0.3"
|
11
11
|
end
|
12
12
|
|
13
|
-
appraise "rails-
|
14
|
-
gem "rails", "
|
13
|
+
appraise "rails-5.1" do
|
14
|
+
gem "rails", "5.1.1"
|
15
15
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 1.2.0 (June 1, 2017)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- Shortcode converted from module to a class (@toddnestor)
|
6
|
+
- Separate instances of Shortcode have separate configurations (@toddnestor)
|
7
|
+
- Updated to parslet 1.8.0
|
8
|
+
- Updated to rspec 3.6
|
9
|
+
- Template loading can be from configuration or file (@toddnestor)
|
10
|
+
|
11
|
+
Misc:
|
12
|
+
|
13
|
+
- Testing against the latest versions of Rails 5.0 & 5.1
|
14
|
+
|
1
15
|
## 1.1.1 (September 14, 2015)
|
2
16
|
|
3
17
|
Features:
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,83 +2,69 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
shortcode (1.1.1)
|
5
|
-
parslet (= 1.
|
5
|
+
parslet (= 1.8.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
appraisal (2.
|
10
|
+
appraisal (2.2.0)
|
11
11
|
bundler
|
12
12
|
rake
|
13
13
|
thor (>= 0.14.0)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
rest-client (>= 1.6.8, < 2)
|
18
|
-
simplecov (~> 0.10.0)
|
14
|
+
coveralls (0.8.21)
|
15
|
+
json (>= 1.8, < 3)
|
16
|
+
simplecov (~> 0.14.1)
|
19
17
|
term-ansicolor (~> 1.3)
|
20
|
-
thor (~> 0.19.
|
21
|
-
|
18
|
+
thor (~> 0.19.4)
|
19
|
+
tins (~> 1.6)
|
20
|
+
diff-lcs (1.3)
|
22
21
|
docile (1.1.5)
|
23
|
-
|
24
|
-
|
25
|
-
haml (4.0.7)
|
22
|
+
haml (5.0.1)
|
23
|
+
temple (>= 0.8.0)
|
26
24
|
tilt
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
mime-types (>= 1.16, < 3.0)
|
38
|
-
netrc (~> 0.7)
|
39
|
-
rspec (3.3.0)
|
40
|
-
rspec-core (~> 3.3.0)
|
41
|
-
rspec-expectations (~> 3.3.0)
|
42
|
-
rspec-mocks (~> 3.3.0)
|
43
|
-
rspec-core (3.3.2)
|
44
|
-
rspec-support (~> 3.3.0)
|
45
|
-
rspec-expectations (3.3.1)
|
25
|
+
json (2.1.0)
|
26
|
+
parslet (1.8.0)
|
27
|
+
rake (12.0.0)
|
28
|
+
rspec (3.6.0)
|
29
|
+
rspec-core (~> 3.6.0)
|
30
|
+
rspec-expectations (~> 3.6.0)
|
31
|
+
rspec-mocks (~> 3.6.0)
|
32
|
+
rspec-core (3.6.0)
|
33
|
+
rspec-support (~> 3.6.0)
|
34
|
+
rspec-expectations (3.6.0)
|
46
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-mocks (3.
|
36
|
+
rspec-support (~> 3.6.0)
|
37
|
+
rspec-mocks (3.6.0)
|
49
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-support (3.
|
52
|
-
simplecov (0.
|
39
|
+
rspec-support (~> 3.6.0)
|
40
|
+
rspec-support (3.6.0)
|
41
|
+
simplecov (0.14.1)
|
53
42
|
docile (~> 1.1.0)
|
54
|
-
json (
|
43
|
+
json (>= 1.8, < 3)
|
55
44
|
simplecov-html (~> 0.10.0)
|
56
|
-
simplecov-html (0.10.
|
57
|
-
slim (3.0.
|
58
|
-
temple (
|
45
|
+
simplecov-html (0.10.1)
|
46
|
+
slim (3.0.8)
|
47
|
+
temple (>= 0.7.6, < 0.9)
|
59
48
|
tilt (>= 1.3.3, < 2.1)
|
60
|
-
temple (0.
|
61
|
-
term-ansicolor (1.
|
49
|
+
temple (0.8.0)
|
50
|
+
term-ansicolor (1.6.0)
|
62
51
|
tins (~> 1.0)
|
63
|
-
thor (0.19.
|
64
|
-
tilt (2.0.
|
65
|
-
tins (1.
|
66
|
-
unf (0.1.4)
|
67
|
-
unf_ext
|
68
|
-
unf_ext (0.0.7.1)
|
52
|
+
thor (0.19.4)
|
53
|
+
tilt (2.0.7)
|
54
|
+
tins (1.14.0)
|
69
55
|
|
70
56
|
PLATFORMS
|
71
57
|
ruby
|
72
58
|
|
73
59
|
DEPENDENCIES
|
74
|
-
appraisal (= 2.
|
75
|
-
bundler (~> 1.
|
76
|
-
coveralls (~> 0)
|
77
|
-
haml (~>
|
78
|
-
rake (~>
|
79
|
-
rspec (~> 3.
|
60
|
+
appraisal (= 2.2.0)
|
61
|
+
bundler (~> 1.15)
|
62
|
+
coveralls (~> 0.8)
|
63
|
+
haml (~> 5.0)
|
64
|
+
rake (~> 12.0)
|
65
|
+
rspec (~> 3.6)
|
80
66
|
shortcode!
|
81
67
|
slim (~> 3.0)
|
82
68
|
|
83
69
|
BUNDLED WITH
|
84
|
-
1.
|
70
|
+
1.15.0
|
data/README.md
CHANGED
@@ -27,8 +27,8 @@ Or install it yourself as:
|
|
27
27
|
$ gem install shortcode
|
28
28
|
```
|
29
29
|
|
30
|
-
Shortcode is tested against ruby version 2.
|
31
|
-
Rails versions
|
30
|
+
Shortcode is tested against ruby version 2.2, 2.3, and 2.4 as well as jruby (2.x compatible), it will not work with ruby 1.8 and is no longer tested against ruby 1.9. Shortcode rails integration is tested against
|
31
|
+
Rails versions 4.1, 4.2, 5.0 and 5.1.
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
@@ -36,8 +36,11 @@ Rails versions 3.2, 4.0, 4.1 and 4.2.
|
|
36
36
|
|
37
37
|
Shortcode is very simple to use, simply call the `process` method and pass it a string containing shortcode markup.
|
38
38
|
|
39
|
+
You can create multiple instances of `Shortcode` with separate configurations for each.
|
40
|
+
|
39
41
|
```ruby
|
40
|
-
Shortcode.
|
42
|
+
shortcode = Shortcode.new
|
43
|
+
shortcode.process("[quote]Hello World[/quote]")
|
41
44
|
```
|
42
45
|
|
43
46
|
In a Rails app, you can create helper methods to handle your shortcoded content and use them in your views with something similar to `<%= content_html @page.content %>`. Those two helper method can be used if your content contains html to be escaped or not.
|
@@ -59,12 +62,23 @@ end
|
|
59
62
|
Any tags you wish to use with Shortcode need to be configured in the setup block, there are 2 types of tag, `block_tags` and `self_closing_tags`. Block tags have a matching open and close tag such as `[quote]A quote[/quote]`, self closing tags have no close tag, for example `[gallery]`. To define the tags Shortcode should parse do so in the configuration (in a Rails initializer for example) as follows:
|
60
63
|
|
61
64
|
```ruby
|
62
|
-
Shortcode.
|
65
|
+
shortcode = Shortcode.new
|
66
|
+
shortcode.setup do |config|
|
63
67
|
config.block_tags = [:quote, :list]
|
64
68
|
config.self_closing_tags = [:gallery, :widget]
|
65
69
|
end
|
66
70
|
```
|
67
71
|
|
72
|
+
Note that you can call the setup block multiple times if need be and add to it.
|
73
|
+
|
74
|
+
For example:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
shortcode.setup do |config|
|
78
|
+
config.block_tags << :other_tag
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
68
82
|
### Templates
|
69
83
|
|
70
84
|
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
|
@@ -118,22 +132,23 @@ The alternative way to define templates is to set them using the `templates` con
|
|
118
132
|
values containing a template string. For instance:
|
119
133
|
|
120
134
|
```ruby
|
121
|
-
Shortcode.
|
135
|
+
shortcode = Shortcode.new
|
136
|
+
|
137
|
+
shortcode.setup do |config|
|
122
138
|
config.templates = { gallery: 'template code' }
|
123
139
|
end
|
124
140
|
```
|
125
141
|
|
126
|
-
|
127
|
-
an exception will be raised.
|
128
|
-
|
129
|
-
Note: it's NOT possible to load templates from a config option AND from the file system, you must either load all templates from the file system or define all templates in a config option.
|
142
|
+
Note: Templates can be loaded from either the file system or the configuration templates. If `check_config_templates_first` is set to true (the default value) on the configuration then it will check configuration templates first, and file system templates if it doesn't find one. If `check_config_templates_first` is set to false on the configuration it will check for a file system template first, and then configuration templates if it doesn't find one. If it doesn't find a template in either spot then it will raise an error.
|
130
143
|
|
131
144
|
### Custom Helpers
|
132
145
|
|
133
146
|
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 templates.
|
134
147
|
|
135
148
|
```ruby
|
136
|
-
Shortcode.
|
149
|
+
shortcode = Shortcode.new
|
150
|
+
|
151
|
+
shortcode.setup do |config|
|
137
152
|
config.helpers = [CustomHelper, AnotherCustomHelper]
|
138
153
|
end
|
139
154
|
```
|
@@ -167,15 +182,15 @@ class GalleryPresenter
|
|
167
182
|
|
168
183
|
private
|
169
184
|
|
170
|
-
|
171
|
-
|
172
|
-
|
185
|
+
def images
|
186
|
+
Image.where("id IN (?)", @attributes[:ids])
|
187
|
+
end
|
173
188
|
end
|
174
189
|
```
|
175
190
|
|
176
191
|
#### Using additional attributes
|
177
192
|
|
178
|
-
At times you may want to pass through additional attributes to a presenter, for instance if you have a [gallery] shortcode tag and you want to pull out all images for a post, this can be
|
193
|
+
At times you may want to pass through additional attributes to a presenter, for instance if you have a [gallery] shortcode tag and you want to pull out all images for a post, this can be achieved using additional attributes with a presenter.
|
179
194
|
|
180
195
|
```ruby
|
181
196
|
class GalleryPresenter
|
@@ -199,34 +214,39 @@ class GalleryPresenter
|
|
199
214
|
|
200
215
|
private
|
201
216
|
|
202
|
-
|
203
|
-
|
204
|
-
|
217
|
+
def images
|
218
|
+
@additional_attributes[:images].map &:url
|
219
|
+
end
|
205
220
|
end
|
221
|
+
```
|
206
222
|
|
207
|
-
|
208
|
-
# as the additional_attributes argument
|
209
|
-
Shortcode.process('[gallery]', { images: @post.images })
|
223
|
+
The hash containing the images attribute is passed through to the presenter as the additional_attributes argument to the `process` method.
|
210
224
|
|
225
|
+
```ruby
|
226
|
+
shortcode = Shortcode.new
|
227
|
+
shortcode.process('[gallery]', { images: @post.images })
|
211
228
|
```
|
212
229
|
|
213
230
|
#### Registering presenters
|
214
231
|
|
215
|
-
To register a presenter simply call `
|
232
|
+
To register a presenter simply call `register_presenter` passing the presenter class e.g.
|
216
233
|
|
217
234
|
```ruby
|
235
|
+
shortcode = Shortcode.new
|
236
|
+
|
218
237
|
# A single presenter
|
219
|
-
|
238
|
+
shortcode.register_presenter(CustomPresenter)
|
220
239
|
|
221
240
|
# Or multiple presenters in one call
|
222
|
-
|
223
|
-
|
241
|
+
shortcode.register_presenter(CustomPresenter, AnotherPresenter)
|
224
242
|
```
|
225
243
|
|
226
244
|
### Configuration
|
227
245
|
|
228
246
|
```ruby
|
229
|
-
Shortcode.
|
247
|
+
shortcode = Shortcode.new
|
248
|
+
|
249
|
+
shortcode.setup do |config|
|
230
250
|
|
231
251
|
# the template parser to use
|
232
252
|
config.template_parser = :erb # :erb, :haml, :slim supported, :erb is default
|
@@ -234,10 +254,12 @@ Shortcode.setup do |config|
|
|
234
254
|
# location of the template files, default is "app/views/shortcode_templates"
|
235
255
|
config.template_path = "support/templates/erb"
|
236
256
|
|
237
|
-
# a hash of templates passed as strings
|
238
|
-
# above template_path option. The default is nil
|
257
|
+
# a hash of templates passed as strings.
|
239
258
|
config.templates = { gallery: 'template code' }
|
240
259
|
|
260
|
+
# a boolean option to set whether configuration templates are checked first or file system templates
|
261
|
+
config.check_config_templates_first = true
|
262
|
+
|
241
263
|
# an array of helper modules to make available within templates
|
242
264
|
config.helpers = [CustomerHelper]
|
243
265
|
|
@@ -256,6 +278,23 @@ Shortcode.setup do |config|
|
|
256
278
|
end
|
257
279
|
```
|
258
280
|
|
281
|
+
### Singleton
|
282
|
+
|
283
|
+
You can optionally use Shortcode as a singleton instance with the same configuration throughout.
|
284
|
+
|
285
|
+
To do this, you call methods directly on the `Shortcode` class.
|
286
|
+
|
287
|
+
For example:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
Shortcode.setup do |config|
|
291
|
+
config.block_tags = [:quote]
|
292
|
+
end
|
293
|
+
|
294
|
+
Shortcode.register_presenter(QuotePresenterClass)
|
295
|
+
|
296
|
+
Shortcode.process('[quote]Some quote[/quote]')
|
297
|
+
```
|
259
298
|
|
260
299
|
## Contributing
|
261
300
|
|
data/gemfiles/rails_4.1.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED