ymdp 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +21 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/ymdp/application_view.rb +153 -116
- data/lib/ymdp/base.rb +22 -1
- data/lib/ymdp/compiler/domains.rb +1 -1
- data/lib/ymdp/compiler/git_helper.rb +18 -15
- data/lib/ymdp/compiler/template.rb +46 -40
- data/lib/ymdp/configuration/config.rb +3 -3
- data/lib/ymdp/processor/compressor.rb +66 -13
- data/lib/ymdp/processor/form_post.rb +2 -2
- data/lib/ymdp/processor/validator.rb +36 -16
- data/lib/ymdp/processor/w3c.rb +20 -18
- data/lib/ymdp/support/file.rb +45 -78
- data/lib/ymdp/translator/base.rb +39 -38
- data/spec/application_view_spec.rb +376 -0
- data/spec/compiler_spec.rb +49 -7
- data/spec/compiler_template_spec.rb +243 -11
- data/spec/compressor_spec.rb +123 -0
- data/spec/configuration_spec.rb +116 -3
- data/spec/file_spec.rb +103 -0
- data/spec/git_helper_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/stubs.rb +42 -2
- data/spec/translator_spec.rb +317 -1
- data/spec/validator_spec.rb +171 -0
- data/spec/ymdp_base_spec.rb +40 -0
- data/ymdp.gemspec +11 -4
- metadata +11 -4
- data/lib/ymdp/helpers.rb +0 -4
- data/lib/ymdp/support/blank.rb +0 -58
data/History.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
== in Git
|
2
|
+
* minor enhancements
|
3
|
+
|
4
|
+
|
5
|
+
== 0.1.7 2010-01-17
|
6
|
+
* minor enhancements
|
7
|
+
* Refactored ApplicationView and the F file support class
|
8
|
+
* improved RDoc coverage
|
9
|
+
* improved test coverage to 89%
|
10
|
+
|
11
|
+
== 0.1.6 2010-01-16
|
12
|
+
* major enhancements
|
13
|
+
* YMDP global settings now assigned through YMDP::Base.configure block
|
14
|
+
* Raise exceptions if vital settings like version and server don't exist
|
15
|
+
* minor enhancements
|
16
|
+
* improved RDoc coverage
|
17
|
+
* improved test coverage
|
18
|
+
* YMDP_ROOT is now replaced by BASE_PATH
|
19
|
+
* renamed YMDP::Base to YMDP::ApplicationView
|
20
|
+
* made new YMDP::Base to handle global settings
|
21
|
+
|
data/Rakefile
CHANGED
@@ -53,7 +53,7 @@ Rake::RDocTask.new do |rdoc|
|
|
53
53
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
54
54
|
|
55
55
|
rdoc.rdoc_dir = 'rdoc'
|
56
|
-
rdoc.title = "
|
56
|
+
rdoc.title = "YMDP #{version}"
|
57
57
|
rdoc.rdoc_files.include('README*')
|
58
58
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
59
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -6,7 +6,6 @@ module YMDP
|
|
6
6
|
# is HTML, JavaScript or CSS.
|
7
7
|
#
|
8
8
|
module ApplicationView
|
9
|
-
include YMDP::FileSupport
|
10
9
|
include YMDP::Compressor
|
11
10
|
|
12
11
|
extend self
|
@@ -125,11 +124,16 @@ module YMDP
|
|
125
124
|
# will find <tt>app/javascripts/shared/sidebar.js</tt> and render its contents into the current
|
126
125
|
# view in an inline script block.
|
127
126
|
#
|
128
|
-
#
|
127
|
+
# == Rendering a stylesheet partial
|
128
|
+
#
|
129
|
+
# Stylesheets are located at <tt>app/stylesheets</tt> and are named <tt>_filename_.css</tt>
|
130
|
+
#
|
129
131
|
#
|
130
|
-
#
|
132
|
+
# === Rendering multiple partials
|
133
|
+
#
|
134
|
+
# Pass an array to <tt>render</tt> to combine multiple files into a single
|
131
135
|
# inline block. This is useful for compression and validation, as it allows a set of
|
132
|
-
#
|
136
|
+
# files to be compressed or validated in a single context.
|
133
137
|
#
|
134
138
|
# render :javascript => ['application', 'flash', 'debug']
|
135
139
|
#
|
@@ -139,47 +143,91 @@ module YMDP
|
|
139
143
|
#
|
140
144
|
# Pass a <tt>:filename</tt> parameter to set the name of the combined file. Currently the
|
141
145
|
# combined file only exists on disc while it's being compressed and/or validated, but
|
142
|
-
# in the future this may be expanded to save multiple
|
146
|
+
# in the future this may be expanded to save multiple files as a single external asset.
|
147
|
+
#
|
148
|
+
# render :javascript = ['application', 'flash', 'debug'], :filename => 'javascripts'
|
143
149
|
#
|
144
150
|
# Currently the <tt>:filename</tt> parameter is simply a convenience.
|
145
151
|
#
|
146
|
-
#
|
152
|
+
# Multiple partials of any type can be rendered.
|
153
|
+
#
|
154
|
+
# For example:
|
147
155
|
#
|
148
|
-
#
|
156
|
+
# render :partial => ['header', 'footer', 'sidebar'], :filename => 'html_layouts'
|
157
|
+
#
|
158
|
+
# will find <tt>app/views/_header.html.haml</tt>, <tt>app/views/_footer.html.haml</tt>,
|
159
|
+
# and <tt>app/views/_sidebar.html.haml</tt> and write them to a temporary file called
|
160
|
+
# <tt>tmp/html_layouts</tt> before rendering that file into the current view.
|
161
|
+
#
|
162
|
+
# This feature is intended mainly for JavaScript and CSS.
|
163
|
+
#
|
164
|
+
# For example:
|
165
|
+
#
|
166
|
+
# render :stylesheet => ['application', 'colors'], :filename => 'styles'
|
167
|
+
#
|
168
|
+
# will render <tt>app/stylesheets/application.css</tt> and <tt>app/stylesheets/colors.css</tt>
|
169
|
+
# as a single temporary file called <tt>tmp/styles</tt> before rendering that file into
|
170
|
+
# the current view.
|
171
|
+
#
|
172
|
+
# If compression and validation options are turned on, the resulting temporary file will be
|
173
|
+
# compressed and/or validated before being rendered into the current view. This will result
|
174
|
+
# in a more efficient compression and a more effective validation.
|
149
175
|
#
|
150
176
|
def render(params)
|
151
177
|
output = []
|
152
|
-
|
153
|
-
|
154
|
-
tags =
|
178
|
+
|
179
|
+
unless params.has_key?(:tags)
|
180
|
+
params[:tags] = true
|
155
181
|
end
|
182
|
+
|
183
|
+
output << render_html_partial(params)
|
184
|
+
output << render_javascript_partial(params)
|
185
|
+
output << render_stylesheet_partial(params)
|
186
|
+
|
187
|
+
output.flatten.join("\n")
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
# Renders an HTML, Haml or ERB partial.
|
193
|
+
#
|
194
|
+
def render_html_partial(params)
|
195
|
+
output = []
|
196
|
+
|
156
197
|
if params[:partial]
|
157
198
|
params[:partial].to_a.each do |partial|
|
158
199
|
output << render_partial(partial)
|
159
200
|
end
|
160
201
|
end
|
161
|
-
|
162
|
-
output << "<script type='text/javascript'>" if tags
|
163
|
-
output << render_javascripts(params[:javascript].to_a, params[:filename])
|
164
|
-
output << "</script>" if tags
|
165
|
-
end
|
166
|
-
if params[:stylesheet]
|
167
|
-
params[:stylesheet].to_a.each do |stylesheet|
|
168
|
-
output << render_stylesheet(stylesheet, tags)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
output.join("\n")
|
202
|
+
output
|
172
203
|
end
|
173
|
-
|
174
|
-
private
|
175
204
|
|
176
|
-
#
|
205
|
+
# Renders an HTML partial.
|
177
206
|
#
|
178
207
|
def render_partial(filename)
|
179
208
|
output = ''
|
209
|
+
path = find_partial(filename)
|
210
|
+
|
211
|
+
if path && File.exists?(path)
|
212
|
+
template = File.read(path)
|
213
|
+
if path =~ /haml$/
|
214
|
+
output = process_haml(template, path)
|
215
|
+
else
|
216
|
+
output = process_template(template)
|
217
|
+
end
|
218
|
+
else
|
219
|
+
raise "Could not find partial: #{filename}"
|
220
|
+
end
|
221
|
+
output
|
222
|
+
end
|
223
|
+
|
224
|
+
# Searches all the possible paths to find a match for this partial name.
|
225
|
+
#
|
226
|
+
def find_partial(filename)
|
180
227
|
path = nil
|
181
|
-
|
182
228
|
["views", "views/shared"].each do |dir|
|
229
|
+
|
230
|
+
# TODO: Refactor this so it doesn't use BASE_PATH
|
183
231
|
basic_path = "#{BASE_PATH}/app/#{dir}/_#{filename}.html"
|
184
232
|
|
185
233
|
["", ".haml", ".erb"].each do |extension|
|
@@ -188,125 +236,114 @@ module YMDP
|
|
188
236
|
end
|
189
237
|
end
|
190
238
|
end
|
191
|
-
|
192
|
-
if path
|
193
239
|
|
194
|
-
|
195
|
-
template = f.read
|
196
|
-
if path =~ /haml$/
|
197
|
-
output = process_haml(template, path)
|
198
|
-
else
|
199
|
-
output = process_template(template)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
else
|
203
|
-
raise "Could not find partial: #{filename}"
|
204
|
-
end
|
205
|
-
output
|
240
|
+
path
|
206
241
|
end
|
207
|
-
|
208
|
-
# Internal use only. Renders a stylesheet partial.
|
209
|
-
#
|
210
|
-
def render_stylesheet(filename, tags=false)
|
211
|
-
unless filename =~ /\.css$/
|
212
|
-
filename = "#{filename}.css"
|
213
|
-
end
|
214
|
-
path = "#{BASE_PATH}/app/stylesheets/#{filename}"
|
215
242
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
if tags
|
229
|
-
"<style type='text/css'>\n" + output + "\n</style>"
|
230
|
-
else
|
231
|
-
output
|
243
|
+
def render_javascript_partial(params)
|
244
|
+
output = []
|
245
|
+
# Render a JavaScript partial.
|
246
|
+
#
|
247
|
+
if params[:javascript]
|
248
|
+
content = render_javascripts(params[:javascript].to_a, params[:filename])
|
249
|
+
unless content.blank?
|
250
|
+
output << "<script type='text/javascript'>" if params[:tags]
|
251
|
+
output << content
|
252
|
+
output << "</script>" if params[:tags]
|
232
253
|
end
|
233
|
-
else
|
234
|
-
""
|
235
254
|
end
|
255
|
+
output
|
236
256
|
end
|
237
257
|
|
238
|
-
#
|
258
|
+
# Renders a JavaScript partial.
|
239
259
|
#
|
240
260
|
def render_javascripts(filenames, combined_filename=nil)
|
241
|
-
|
261
|
+
filenames_str = combined_filename || filenames.join()
|
242
262
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
output << render_without_compression(filename, false)
|
263
|
+
filenames.map! do |filename|
|
264
|
+
filename.gsub!(/\.js$/, "")
|
265
|
+
"#{BASE_PATH}/app/javascripts/#{filename}.js"
|
247
266
|
end
|
248
|
-
output = output.join("\n")
|
249
267
|
|
250
|
-
|
268
|
+
output = combine_files(filenames)
|
251
269
|
tmp_filename = "./tmp/#{filenames_str}.js"
|
252
270
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
validate_filename = tmp_filename
|
257
|
-
end
|
258
|
-
|
259
|
-
# return compressed javascript or else don't
|
260
|
-
output = YMDP::Compressor::JavaScript.compress(tmp_filename) || output
|
271
|
+
validate = F.save_to_file(output, tmp_filename)
|
272
|
+
|
273
|
+
output = YMDP::Compressor::JavaScript.compress(tmp_filename) if CONFIG.compress_embedded_js?
|
261
274
|
|
262
|
-
YMDP::Validator::JavaScript.validate(
|
275
|
+
YMDP::Validator::JavaScript.validate(tmp_filename) if validate && CONFIG.validate_embedded_js?
|
263
276
|
|
264
277
|
output
|
265
278
|
end
|
266
279
|
|
267
|
-
#
|
268
|
-
# compression, so they can be compressed as a single block.
|
280
|
+
# Render a CSS partial.
|
269
281
|
#
|
270
|
-
def
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
if File.exists?(path)
|
279
|
-
File.open(path) do |f|
|
280
|
-
template = f.read
|
281
|
-
output = process_template(template)
|
282
|
-
end
|
283
|
-
|
284
|
-
if tags
|
285
|
-
"<script type='text/javascript'>\n" + output + "\n</script>"
|
286
|
-
else
|
287
|
-
output
|
282
|
+
def render_stylesheet_partial(params)
|
283
|
+
output = []
|
284
|
+
if params[:stylesheet]
|
285
|
+
content = render_stylesheets(params[:stylesheet].to_a, params[:filename])
|
286
|
+
unless content.blank?
|
287
|
+
output << "<style type='text/css'>" if params[:tags]
|
288
|
+
output << content
|
289
|
+
output << "</style>" if params[:tags]
|
288
290
|
end
|
289
|
-
else
|
290
|
-
""
|
291
291
|
end
|
292
|
+
output
|
292
293
|
end
|
293
294
|
|
294
|
-
#
|
295
|
+
# Renders a JavaScript partial.
|
295
296
|
#
|
296
|
-
def
|
297
|
-
|
298
|
-
tmp_filename = "
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
297
|
+
def render_stylesheets(filenames, combined_filename=nil)
|
298
|
+
filenames_str = combined_filename || filenames.join()
|
299
|
+
tmp_filename = "./tmp/#{filenames_str}.css"
|
300
|
+
|
301
|
+
filenames.map! do |filename|
|
302
|
+
filename.gsub!(/\.css$/, "")
|
303
|
+
"#{BASE_PATH}/app/stylesheets/#{filename}.css"
|
304
|
+
end
|
305
|
+
|
306
|
+
output = combine_files(filenames)
|
307
|
+
|
308
|
+
validate = F.save_to_file(output, tmp_filename)
|
304
309
|
|
305
|
-
|
306
|
-
|
310
|
+
output = YMDP::Compressor::Stylesheet.compress(tmp_filename) if CONFIG.compress_css?
|
311
|
+
|
312
|
+
# YMDP::Validator::Stylesheet.validate(tmp_filename) if validate && CONFIG.validate_embedded_css?
|
313
|
+
|
314
|
+
output
|
315
|
+
end
|
316
|
+
|
317
|
+
# Concatenates all javascript files into one long string.
|
318
|
+
#
|
319
|
+
def combine_files(filenames)
|
320
|
+
output = []
|
321
|
+
filenames.each do |filename|
|
322
|
+
output << render_without_compression(filename, false)
|
307
323
|
end
|
324
|
+
output.join("\n")
|
325
|
+
end
|
326
|
+
|
327
|
+
# Renders together a set of JavaScript files without
|
328
|
+
# compression, so they can be compressed as a single block.
|
329
|
+
#
|
330
|
+
def render_without_compression(path, tags=true)
|
331
|
+
output = ""
|
308
332
|
|
309
|
-
|
333
|
+
if File.exists?(path)
|
334
|
+
template = File.read(path)
|
335
|
+
output = process_template(template)
|
336
|
+
end
|
337
|
+
|
338
|
+
output
|
310
339
|
end
|
311
340
|
end
|
341
|
+
|
342
|
+
class View
|
343
|
+
include YMDP::ApplicationView
|
344
|
+
|
345
|
+
def initialize(assets_directory)
|
346
|
+
@assets_directory = assets_directory
|
347
|
+
end
|
348
|
+
end
|
312
349
|
end
|
data/lib/ymdp/base.rb
CHANGED
@@ -78,7 +78,28 @@ module YMDP
|
|
78
78
|
#
|
79
79
|
def paths
|
80
80
|
self.class.paths
|
81
|
-
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.base_path
|
84
|
+
paths[:base_path]
|
85
|
+
end
|
86
|
+
|
87
|
+
def base_path
|
88
|
+
self.class.base_path
|
89
|
+
end
|
90
|
+
|
91
|
+
# Parses out the <tt>base_path</tt> setting from a path to display it in a
|
92
|
+
# less verbose way.
|
93
|
+
#
|
94
|
+
def self.display_path(path)
|
95
|
+
path = File.expand_path(path)
|
96
|
+
path.gsub(base_path.to_s, "")
|
97
|
+
end
|
98
|
+
|
99
|
+
def display_path(path)
|
100
|
+
self.class.display_path(path)
|
101
|
+
end
|
102
|
+
|
82
103
|
|
83
104
|
private
|
84
105
|
|
@@ -1,23 +1,26 @@
|
|
1
|
+
require 'support/file'
|
1
2
|
require 'grit'
|
2
3
|
include Grit
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
branch
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module YMDP
|
6
|
+
class GitHelper
|
7
|
+
def get_hash(branch)
|
8
|
+
branch = get_current_branch || "master"
|
9
|
+
repo = Repo.new("#{BASE_PATH}/.")
|
10
|
+
repo.commits(branch).first.id
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def get_current_branch
|
14
|
+
result = F.execute("git status", :return => true)
|
15
|
+
if result =~ /# On branch (.*)/
|
16
|
+
return $1
|
17
|
+
end
|
15
18
|
end
|
16
|
-
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def do_commit(message)
|
21
|
+
repo = Repo.new(".")
|
22
|
+
repo.add(".")
|
23
|
+
$stdout.puts F.execute("git commit -am \"#{message}\"", :return => true)
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|