engine_of_war 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,11 +23,10 @@ Gem::Specification.new do |gem|
23
23
  gem.add_dependency 'haml'
24
24
  gem.add_dependency 'sass', ">= 3.1.7"
25
25
  gem.add_dependency "RedCloth"
26
+ gem.add_dependency "rdiscount"
26
27
  gem.add_dependency "coffee-script"
27
- gem.add_dependency "redcarpet"
28
28
 
29
29
  gem.add_development_dependency "yard"
30
- gem.add_development_dependency "RedCloth"
31
30
  gem.add_development_dependency "rake"
32
31
  gem.add_development_dependency "rspec"
33
32
  gem.add_development_dependency "capybara"
data/lib/engine_of_war.rb CHANGED
@@ -15,7 +15,9 @@ module EngineOfWar; end
15
15
 
16
16
  require 'engine_of_war/version'
17
17
  require 'engine_of_war/extensions/string'
18
- require 'engine_of_war/my_red_cloth_template'
18
+ require 'engine_of_war/template_engines/filters'
19
+ require 'engine_of_war/template_engines/textile'
20
+ require 'engine_of_war/template_engines/markdown'
19
21
  require 'engine_of_war/layout'
20
22
  require 'engine_of_war/page'
21
23
  require 'engine_of_war/page_collection'
@@ -0,0 +1,78 @@
1
+ module EngineOfWar::TemplateEngines
2
+ module Filters
3
+ BASE_IMAGE_URL = "/images"
4
+ include Padrino::Helpers::TagHelpers
5
+
6
+ def code_filter(txt)
7
+ txt.gsub(/@@@ *(\w*)\r?\n? *(.+?)\r?\n?@@@/m) do
8
+ klass = $1.present? ? " class=\"#{$1.downcase}\"" : ""
9
+ "<pre><code#{klass}>#{$2}</code></pre>"
10
+ end
11
+ end
12
+
13
+ def image_filter(txt)
14
+ txt.gsub(/^%([<>]?)([0-9a-zA-Z_.-]+)([^%]*)%/) do
15
+ float = $1
16
+ image_id = $2
17
+ size = $3
18
+
19
+ float = :right if float == '>'
20
+ float = :left if float == '<'
21
+
22
+ uploaded_image_tag(image_id, :size => size, :float => float)
23
+ end
24
+ end
25
+
26
+ def uploaded_image_tag(image_name, opts = {})
27
+ opts.symbolize_keys
28
+
29
+ opts[:size] = "original" if opts[:size].blank?
30
+ opts[:size].strip!
31
+
32
+ basename, ext = image_name.split('.')
33
+ image_src = "#{BASE_IMAGE_URL}/#{basename}/#{opts[:size]}.#{ext}"
34
+ meta = meta_for_image(basename)
35
+
36
+ return unknown_image_tag(image_name) unless image_directory_exists?(basename)
37
+
38
+ image_options = { :src => image_src }
39
+ image_options[:class] = "float-#{opts[:float]}" if opts[:float]
40
+ image_options[:alt] = meta[:description] if meta[:description]
41
+
42
+ href = meta[:source_url]
43
+
44
+ img_tag = content_tag :img, "", image_options
45
+ if href
46
+ return "<a href='#{href}'>#{img_tag}</a>"
47
+ else
48
+ return img_tag
49
+ end
50
+ end
51
+
52
+ def unknown_image_tag(name)
53
+ "<div class='warning'>unknown image #{name}</div>"
54
+ end
55
+
56
+ def image_directory_exists?(basename)
57
+ File.directory?(image_basedir(basename))
58
+ end
59
+
60
+ def image_basedir(basename)
61
+ File.join(EngineOfWar::App.settings.public_folder, BASE_IMAGE_URL, basename)
62
+ end
63
+
64
+ def meta_for_image(basename)
65
+ file = File.join(image_basedir(basename), "meta.yml")
66
+ if File.exist?(file)
67
+ YAML.load_file(file).delete_if {|k, v| v.blank? }
68
+ else
69
+ {}
70
+ end
71
+ end
72
+
73
+ # Required to confuse padrino
74
+ def block_is_template?(_)
75
+ false
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,12 @@
1
+ module EngineOfWar::TemplateEngines
2
+ class Markdown < Tilt::RDiscountTemplate
3
+ Tilt.register self, "markdown"
4
+
5
+ include EngineOfWar::TemplateEngines::Filters
6
+
7
+ def prepare
8
+ @engine = RDiscount.new(image_filter(code_filter(data)))
9
+ @output = nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module EngineOfWar::TemplateEngines
2
+ class Textile < Tilt::RedClothTemplate
3
+ Tilt.register self, "textile"
4
+ include EngineOfWar::TemplateEngines::Filters
5
+
6
+ def prepare
7
+ @engine = RedCloth.new(image_filter(code_filter(data)))
8
+ @output = nil
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module EngineOfWar
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -71,3 +71,21 @@ describe "given a textile template with an image link " do
71
71
  end
72
72
  end
73
73
 
74
+ describe "given a textile template with an image link " do
75
+ before { create_template("layouts/application.html.haml", "%h1 Layout\n= yield") }
76
+
77
+ describe "and an image link" do
78
+ before do
79
+ create_asset("images/file/original.jpg", "image data")
80
+ create_template("posts/bar.html.markdown", "# Title\n%file.jpg%\n")
81
+ end
82
+
83
+ context "the rendered page" do
84
+ before { visit "/posts/bar" }
85
+ subject { page }
86
+
87
+ it { should have_selector('img[src="/images/file/original.jpg"]') }
88
+ end
89
+ end
90
+ end
91
+
@@ -44,6 +44,18 @@ describe "given a layout" do
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ describe "and a markdown template" do
49
+ before { create_template("bar.html.markdown", "# Markdown") }
50
+
51
+ context "on GET to /bar" do
52
+ before { visit "/bar" }
53
+
54
+ it "renders the template" do
55
+ page.should have_selector('h1:contains("Markdown")')
56
+ end
57
+ end
58
+ end
47
59
  end
48
60
 
49
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engine_of_war
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-31 00:00:00.000000000 Z
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70108237554440 !ruby/object:Gem::Requirement
16
+ requirement: &70142151693300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70108237554440
24
+ version_requirements: *70142151693300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: compass
27
- requirement: &70108237569960 !ruby/object:Gem::Requirement
27
+ requirement: &70142151692780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70108237569960
35
+ version_requirements: *70142151692780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: padrino
38
- requirement: &70108237569400 !ruby/object:Gem::Requirement
38
+ requirement: &70142151692140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70108237569400
46
+ version_requirements: *70142151692140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: active_support
49
- requirement: &70108237568520 !ruby/object:Gem::Requirement
49
+ requirement: &70142151691560 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70108237568520
57
+ version_requirements: *70142151691560
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: builder
60
- requirement: &70108237567700 !ruby/object:Gem::Requirement
60
+ requirement: &70142151691000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70108237567700
68
+ version_requirements: *70142151691000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: haml
71
- requirement: &70108237566980 !ruby/object:Gem::Requirement
71
+ requirement: &70142151690540 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70108237566980
79
+ version_requirements: *70142151690540
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sass
82
- requirement: &70108237565800 !ruby/object:Gem::Requirement
82
+ requirement: &70142151708880 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 3.1.7
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70108237565800
90
+ version_requirements: *70142151708880
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: RedCloth
93
- requirement: &70108237564600 !ruby/object:Gem::Requirement
93
+ requirement: &70142151706980 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70108237564600
101
+ version_requirements: *70142151706980
102
102
  - !ruby/object:Gem::Dependency
103
- name: coffee-script
104
- requirement: &70108237563740 !ruby/object:Gem::Requirement
103
+ name: rdiscount
104
+ requirement: &70142151704900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70108237563740
112
+ version_requirements: *70142151704900
113
113
  - !ruby/object:Gem::Dependency
114
- name: redcarpet
115
- requirement: &70108237562580 !ruby/object:Gem::Requirement
114
+ name: coffee-script
115
+ requirement: &70142151703820 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,21 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70108237562580
123
+ version_requirements: *70142151703820
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yard
126
- requirement: &70108237577620 !ruby/object:Gem::Requirement
127
- none: false
128
- requirements:
129
- - - ! '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: *70108237577620
135
- - !ruby/object:Gem::Dependency
136
- name: RedCloth
137
- requirement: &70108237576260 !ruby/object:Gem::Requirement
126
+ requirement: &70142151702420 !ruby/object:Gem::Requirement
138
127
  none: false
139
128
  requirements:
140
129
  - - ! '>='
@@ -142,10 +131,10 @@ dependencies:
142
131
  version: '0'
143
132
  type: :development
144
133
  prerelease: false
145
- version_requirements: *70108237576260
134
+ version_requirements: *70142151702420
146
135
  - !ruby/object:Gem::Dependency
147
136
  name: rake
148
- requirement: &70108237574780 !ruby/object:Gem::Requirement
137
+ requirement: &70142151701340 !ruby/object:Gem::Requirement
149
138
  none: false
150
139
  requirements:
151
140
  - - ! '>='
@@ -153,10 +142,10 @@ dependencies:
153
142
  version: '0'
154
143
  type: :development
155
144
  prerelease: false
156
- version_requirements: *70108237574780
145
+ version_requirements: *70142151701340
157
146
  - !ruby/object:Gem::Dependency
158
147
  name: rspec
159
- requirement: &70108237573780 !ruby/object:Gem::Requirement
148
+ requirement: &70142151700820 !ruby/object:Gem::Requirement
160
149
  none: false
161
150
  requirements:
162
151
  - - ! '>='
@@ -164,10 +153,10 @@ dependencies:
164
153
  version: '0'
165
154
  type: :development
166
155
  prerelease: false
167
- version_requirements: *70108237573780
156
+ version_requirements: *70142151700820
168
157
  - !ruby/object:Gem::Dependency
169
158
  name: capybara
170
- requirement: &70108237571780 !ruby/object:Gem::Requirement
159
+ requirement: &70142151718580 !ruby/object:Gem::Requirement
171
160
  none: false
172
161
  requirements:
173
162
  - - ! '>='
@@ -175,10 +164,10 @@ dependencies:
175
164
  version: '0'
176
165
  type: :development
177
166
  prerelease: false
178
- version_requirements: *70108237571780
167
+ version_requirements: *70142151718580
179
168
  - !ruby/object:Gem::Dependency
180
169
  name: guard-rspec
181
- requirement: &70108237570700 !ruby/object:Gem::Requirement
170
+ requirement: &70142151717960 !ruby/object:Gem::Requirement
182
171
  none: false
183
172
  requirements:
184
173
  - - ! '>='
@@ -186,10 +175,10 @@ dependencies:
186
175
  version: '0'
187
176
  type: :development
188
177
  prerelease: false
189
- version_requirements: *70108237570700
178
+ version_requirements: *70142151717960
190
179
  - !ruby/object:Gem::Dependency
191
180
  name: guard-bundler
192
- requirement: &70108237570160 !ruby/object:Gem::Requirement
181
+ requirement: &70142151717060 !ruby/object:Gem::Requirement
193
182
  none: false
194
183
  requirements:
195
184
  - - ! '>='
@@ -197,10 +186,10 @@ dependencies:
197
186
  version: '0'
198
187
  type: :development
199
188
  prerelease: false
200
- version_requirements: *70108237570160
189
+ version_requirements: *70142151717060
201
190
  - !ruby/object:Gem::Dependency
202
191
  name: ruby_gntp
203
- requirement: &70108237597940 !ruby/object:Gem::Requirement
192
+ requirement: &70142151715400 !ruby/object:Gem::Requirement
204
193
  none: false
205
194
  requirements:
206
195
  - - ! '>='
@@ -208,7 +197,7 @@ dependencies:
208
197
  version: '0'
209
198
  type: :development
210
199
  prerelease: false
211
- version_requirements: *70108237597940
200
+ version_requirements: *70142151715400
212
201
  description: Semi-static site engine.
213
202
  email:
214
203
  - us@thunderboltlabs.com
@@ -229,10 +218,12 @@ files:
229
218
  - lib/engine_of_war/app.rb
230
219
  - lib/engine_of_war/extensions/string.rb
231
220
  - lib/engine_of_war/layout.rb
232
- - lib/engine_of_war/my_red_cloth_template.rb
233
221
  - lib/engine_of_war/page.rb
234
222
  - lib/engine_of_war/page_collection.rb
235
223
  - lib/engine_of_war/recommendation.rb
224
+ - lib/engine_of_war/template_engines/filters.rb
225
+ - lib/engine_of_war/template_engines/markdown.rb
226
+ - lib/engine_of_war/template_engines/textile.rb
236
227
  - lib/engine_of_war/version.rb
237
228
  - spec/assets_spec.rb
238
229
  - spec/atom_spec.rb
@@ -261,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
252
  version: '0'
262
253
  segments:
263
254
  - 0
264
- hash: -2237797161062771447
255
+ hash: 1663746265125056652
265
256
  required_rubygems_version: !ruby/object:Gem::Requirement
266
257
  none: false
267
258
  requirements:
@@ -270,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
261
  version: '0'
271
262
  segments:
272
263
  - 0
273
- hash: -2237797161062771447
264
+ hash: 1663746265125056652
274
265
  requirements: []
275
266
  rubyforge_project:
276
267
  rubygems_version: 1.8.11
@@ -1,78 +0,0 @@
1
- class EngineOfWar::RedClothTemplate < Tilt::RedClothTemplate
2
- Tilt.register self, "textile"
3
-
4
- BASE_IMAGE_URL = "/images"
5
- include Padrino::Helpers::TagHelpers
6
-
7
- def prepare
8
- @engine = RedCloth.new(image_filter(code_filter(data)))
9
- @output = nil
10
- end
11
-
12
- private
13
-
14
- def code_filter(txt)
15
- txt.gsub(/@@@ *(\w*)\r?\n? *(.+?)\r?\n?@@@/m) do
16
- klass = $1.present? ? " class=\"#{$1.downcase}\"" : ""
17
- "<pre><code#{klass}>#{$2}</code></pre>"
18
- end
19
- end
20
-
21
- def image_filter(txt)
22
- txt.gsub(/^%([<>]?)([0-9a-zA-Z_.-]+)([^%]*)%/) do
23
- float = $1
24
- image_id = $2
25
- size = $3
26
-
27
- float = :right if float == '>'
28
- float = :left if float == '<'
29
-
30
- uploaded_image_tag(image_id, :size => size, :float => float)
31
- end
32
- end
33
-
34
- def uploaded_image_tag(image_name, opts = {})
35
- opts.symbolize_keys
36
-
37
- opts[:size] = "original" if opts[:size].blank?
38
- opts[:size].strip!
39
-
40
- basename, ext = image_name.split('.')
41
- image_src = "#{BASE_IMAGE_URL}/#{basename}/#{opts[:size]}.#{ext}"
42
- meta = meta_for_image(basename)
43
-
44
- return "<div class='warning'>unknown image #{image_name}</div>" unless File.directory?(image_basedir(basename))
45
-
46
- image_options = { :src => image_src }
47
- image_options[:class] = "float-#{opts[:float]}" if opts[:float]
48
- image_options[:alt] = meta[:description] if meta[:description]
49
-
50
- href = meta[:source_url]
51
-
52
- img_tag = content_tag :img, "", image_options
53
- if href
54
- return "<a href='#{href}'>#{img_tag}</a>"
55
- else
56
- return img_tag
57
- end
58
- end
59
-
60
- def image_basedir(basename)
61
- File.join(EngineOfWar::App.settings.public_folder, BASE_IMAGE_URL, basename)
62
- end
63
-
64
- def meta_for_image(basename)
65
- file = File.join(image_basedir(basename), "meta.yml")
66
- if File.exist?(file)
67
- YAML.load_file(file).delete_if {|k, v| v.blank? }
68
- else
69
- {}
70
- end
71
- end
72
-
73
- # Required to confuse padrino
74
- def block_is_template?(_)
75
- false
76
- end
77
- end
78
-