shortcode 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -79,6 +79,8 @@ And the haml template to render the shortcode
79
79
  %span.author= @attributes[:author]
80
80
  ```
81
81
 
82
+ If using the gem within a Rails project you can use the Rails helper methods within template files.
83
+
82
84
  Shortcodes can be nested inside other shortcodes, there are no limits imposed on the nesting depth. This can be useful when creating complex content such as a collapsible list that can have any content inside each element. We could have the following shortcodes
83
85
 
84
86
  [collapsible_list]
@@ -0,0 +1,3 @@
1
+ class Shortcode::Tag
2
+ include ActionView::Helpers
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Shortcode
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/shortcode.rb CHANGED
@@ -41,3 +41,4 @@ require 'shortcode/presenter'
41
41
  require 'shortcode/transformer'
42
42
  require 'shortcode/tag'
43
43
  require 'shortcode/exceptions'
44
+ require 'shortcode/railtie' if defined?(Rails)
data/shortcode.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rails", "~> 4"
27
28
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "rails helpers" do
4
+
5
+ let(:template) { load_fixture :rails_helper }
6
+ let(:haml_output) { load_fixture :rails_helper_output_haml, :html }
7
+ let(:erb_output) { load_fixture :rails_helper_output_erb, :html }
8
+
9
+ describe "haml" do
10
+
11
+ it "are accessible within haml templates" do
12
+ Shortcode.process(template).gsub("\n",'').should == haml_output.gsub("\n",'')
13
+ end
14
+
15
+ end
16
+
17
+ describe "erb" do
18
+
19
+ before(:each) do
20
+ Shortcode.setup do |config|
21
+ config.template_parser = :erb
22
+ config.template_path = File.join File.dirname(__FILE__), "support/templates/erb"
23
+ end
24
+ end
25
+
26
+ it "are accessible within haml templates" do
27
+ Shortcode.process(template).gsub("\n",'').should == erb_output.gsub("\n",'')
28
+ end
29
+
30
+ end
31
+
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
  require 'rspec'
3
+ require 'rails'
4
+ require 'action_view'
3
5
  require 'shortcode'
4
6
  require 'support/fixtures'
5
7
 
@@ -11,7 +13,7 @@ RSpec.configure do |config|
11
13
  Shortcode.setup do |config|
12
14
  config.template_parser = :haml
13
15
  config.template_path = File.join File.dirname(__FILE__), "support/templates/haml"
14
- config.block_tags = [:quote, :collapsible_list, :item, :timeline_person]
16
+ config.block_tags = [:quote, :collapsible_list, :item, :timeline_person, :rails_helper]
15
17
  config.self_closing_tags = [:timeline_event, :timeline_info]
16
18
  end
17
19
  end
@@ -0,0 +1 @@
1
+ [rails_helper]blah[/rails_helper]
@@ -0,0 +1 @@
1
+ <b>blah</b>
@@ -0,0 +1 @@
1
+ <p>blah</p>
@@ -0,0 +1 @@
1
+ <%= content_tag(:b, @content) %>
@@ -0,0 +1 @@
1
+ = content_tag(: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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '4'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '4'
94
110
  description: Gem for parsing wordpress style shortcodes
95
111
  email:
96
112
  - jamie@kernowsoul.com
@@ -109,6 +125,7 @@ files:
109
125
  - lib/shortcode/exceptions.rb
110
126
  - lib/shortcode/parser.rb
111
127
  - lib/shortcode/presenter.rb
128
+ - lib/shortcode/railtie.rb
112
129
  - lib/shortcode/tag.rb
113
130
  - lib/shortcode/transformer.rb
114
131
  - lib/shortcode/version.rb
@@ -116,6 +133,7 @@ files:
116
133
  - spec/parser_spec.rb
117
134
  - spec/performance_spec.rb
118
135
  - spec/presenter_spec.rb
136
+ - spec/rails_helpers_spec.rb
119
137
  - spec/shortcode_spec.rb
120
138
  - spec/spec_helper.rb
121
139
  - spec/support/fixtures.rb
@@ -126,6 +144,9 @@ files:
126
144
  - spec/support/fixtures/long_text.txt
127
145
  - spec/support/fixtures/quote_with_extras.txt
128
146
  - spec/support/fixtures/quote_with_extras_output.html
147
+ - spec/support/fixtures/rails_helper.txt
148
+ - spec/support/fixtures/rails_helper_output_erb.html
149
+ - spec/support/fixtures/rails_helper_output_haml.html
129
150
  - spec/support/fixtures/simple_list.txt
130
151
  - spec/support/fixtures/simple_list_output.html
131
152
  - spec/support/fixtures/simple_quote.txt
@@ -138,9 +159,11 @@ files:
138
159
  - spec/support/fixtures/timeline_person.txt
139
160
  - spec/support/fixtures/timeline_person_output.html
140
161
  - spec/support/templates/erb/quote.html.erb
162
+ - spec/support/templates/erb/rails_helper.html.erb
141
163
  - spec/support/templates/haml/collapsible_list.html.haml
142
164
  - spec/support/templates/haml/item.html.haml
143
165
  - spec/support/templates/haml/quote.html.haml
166
+ - spec/support/templates/haml/rails_helper.html.haml
144
167
  - spec/support/templates/haml/timeline_event.html.haml
145
168
  - spec/support/templates/haml/timeline_info.html.haml
146
169
  - spec/support/templates/haml/timeline_person.html.haml
@@ -175,6 +198,7 @@ test_files:
175
198
  - spec/parser_spec.rb
176
199
  - spec/performance_spec.rb
177
200
  - spec/presenter_spec.rb
201
+ - spec/rails_helpers_spec.rb
178
202
  - spec/shortcode_spec.rb
179
203
  - spec/spec_helper.rb
180
204
  - spec/support/fixtures.rb
@@ -185,6 +209,9 @@ test_files:
185
209
  - spec/support/fixtures/long_text.txt
186
210
  - spec/support/fixtures/quote_with_extras.txt
187
211
  - spec/support/fixtures/quote_with_extras_output.html
212
+ - spec/support/fixtures/rails_helper.txt
213
+ - spec/support/fixtures/rails_helper_output_erb.html
214
+ - spec/support/fixtures/rails_helper_output_haml.html
188
215
  - spec/support/fixtures/simple_list.txt
189
216
  - spec/support/fixtures/simple_list_output.html
190
217
  - spec/support/fixtures/simple_quote.txt
@@ -197,9 +224,11 @@ test_files:
197
224
  - spec/support/fixtures/timeline_person.txt
198
225
  - spec/support/fixtures/timeline_person_output.html
199
226
  - spec/support/templates/erb/quote.html.erb
227
+ - spec/support/templates/erb/rails_helper.html.erb
200
228
  - spec/support/templates/haml/collapsible_list.html.haml
201
229
  - spec/support/templates/haml/item.html.haml
202
230
  - spec/support/templates/haml/quote.html.haml
231
+ - spec/support/templates/haml/rails_helper.html.haml
203
232
  - spec/support/templates/haml/timeline_event.html.haml
204
233
  - spec/support/templates/haml/timeline_info.html.haml
205
234
  - spec/support/templates/haml/timeline_person.html.haml