ymdp 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- 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/lib/ymdp/processor/w3c.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
class W3CPoster
|
2
|
+
def self.post_file_to_w3c_validator(file_path, doc_type)
|
3
|
+
query = MultipartPost.build_form_data(
|
4
|
+
:uploaded_file => File.new(file_path, 'r'),
|
5
|
+
:charset => '(detect automatically)',
|
6
|
+
:doctype => doc_type,
|
7
|
+
:group => '1'
|
8
|
+
)
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
Net::HTTP.start('validator.w3.org') do |http|
|
11
|
+
http.post2("/check", query, MultipartPost::REQ_HEADER)
|
12
|
+
end
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
def valid_response?(w3c_response)
|
15
|
-
|
16
|
-
|
17
|
-
end
|
15
|
+
def self.valid_response?(w3c_response)
|
16
|
+
html = w3c_response.read_body
|
17
|
+
html.include? "[Valid]"
|
18
|
+
end
|
18
19
|
|
19
|
-
def w3c_valid?(file_path)
|
20
|
-
|
21
|
-
|
22
|
-
end
|
20
|
+
def self.w3c_valid?(file_path)
|
21
|
+
resp = post_file_to_w3c_validator(file_path, 'HTML 4.01 Strict')
|
22
|
+
valid_response?(resp)
|
23
|
+
end
|
24
|
+
end
|
data/lib/ymdp/support/file.rb
CHANGED
@@ -1,96 +1,63 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Provides a wrapper around common calls that interact with the file system.
|
2
|
+
#
|
3
|
+
module F
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Concatenates together the contents of all the files in the <tt>source_path</tt>
|
8
|
+
# into the <tt>destination_path</tt>.
|
3
9
|
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def concat_files(source_path, destination_path)
|
9
|
-
File.open(destination_path, "a") do |output|
|
10
|
-
Dir[source_path].each do |path|
|
11
|
-
File.open(path) do |f|
|
12
|
-
output.puts f.read
|
13
|
-
end
|
14
|
-
end
|
10
|
+
def concat_files(source_path, destination_path)
|
11
|
+
File.open(destination_path, "a") do |output|
|
12
|
+
Dir[source_path].each do |path|
|
13
|
+
output.puts File.read(path)
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Parses out the <tt>BASE_PATH</tt> constant from filenames to display them in a
|
34
|
-
# friendlier way.
|
35
|
-
#
|
36
|
-
# TODO: Refactor this so it doesn't use a constant.
|
37
|
-
#
|
38
|
-
def display_path(path)
|
39
|
-
path = File.expand_path(path)
|
40
|
-
path.gsub(BASE_PATH, "")
|
41
|
-
end
|
42
|
-
|
43
|
-
# Saves the <tt>output</tt> string to the <tt>destination_path</tt> given
|
44
|
-
#
|
45
|
-
def save_to_file(output, destination_path)
|
46
|
-
unless File.exists?(destination_path)
|
47
|
-
File.open(destination_path, "w") do |w|
|
48
|
-
w.write(output)
|
49
|
-
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Saves the <tt>output</tt> string to the <tt>destination_path</tt> given.
|
19
|
+
#
|
20
|
+
# Returns <tt>true</tt> if the destination file was newly created, <tt>false</tt> if
|
21
|
+
# it already existed.
|
22
|
+
#
|
23
|
+
def save_to_file(output, destination_path)
|
24
|
+
if File.exists?(destination_path)
|
25
|
+
false
|
26
|
+
else
|
27
|
+
File.open(destination_path, "w") do |w|
|
28
|
+
w.write(output)
|
50
29
|
end
|
30
|
+
true
|
51
31
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
output += "\n"
|
67
|
-
|
68
|
-
3.times do |i|
|
69
|
-
line = lines[line_number-(3-i)]
|
70
|
-
output += line if line
|
71
|
-
end
|
72
|
-
|
73
|
-
output += "\n"
|
74
|
-
|
75
|
-
output
|
32
|
+
end
|
33
|
+
|
34
|
+
# Given a <tt>path</tt> and <tt>line_number</tt>, returns the line and two lines previous
|
35
|
+
#
|
36
|
+
# Used for displaying validation errors.
|
37
|
+
#
|
38
|
+
def get_line_from_file(path, line_number)
|
39
|
+
line_number = line_number.to_i
|
40
|
+
output = "\n"
|
41
|
+
lines = File.readlines(path)
|
42
|
+
|
43
|
+
3.times do |i|
|
44
|
+
line = lines[line_number-(3-i)]
|
45
|
+
output += line if line
|
76
46
|
end
|
47
|
+
|
48
|
+
output += "\n"
|
49
|
+
output
|
77
50
|
end
|
78
|
-
end
|
79
51
|
|
80
|
-
# Provide a wrapper around system calls so they can be mocked in tests.
|
81
|
-
#
|
82
|
-
class F
|
83
|
-
extend YMDP::FileSupport
|
84
|
-
|
85
52
|
# Execute a system command. If the parameter <tt>:return</tt> is true, execute the command
|
86
53
|
# with the backtick (`) command and return the results. Otherwise, just execute the command
|
87
54
|
# and let the output go to the screen.
|
88
55
|
#
|
89
|
-
def
|
56
|
+
def execute(command, params={})
|
90
57
|
if params[:return]
|
91
58
|
`#{command}`
|
92
59
|
else
|
93
|
-
system command
|
60
|
+
Kernel.system command
|
94
61
|
end
|
95
62
|
end
|
96
63
|
end
|
data/lib/ymdp/translator/base.rb
CHANGED
@@ -4,12 +4,12 @@ require 'timer'
|
|
4
4
|
require 'compiler/template'
|
5
5
|
|
6
6
|
module YMDP
|
7
|
-
module Yaml
|
8
|
-
module Support
|
7
|
+
module Yaml #:nodoc:
|
8
|
+
module Support #:nodoc:
|
9
9
|
FILENAME_REGEXP = /(.*)_(..-..)\.yml$/
|
10
10
|
|
11
11
|
def language_path(lang)
|
12
|
-
"#{
|
12
|
+
"#{base_path}/app/assets/yrb/#{lang}"
|
13
13
|
end
|
14
14
|
|
15
15
|
def base_filename(path)
|
@@ -31,12 +31,12 @@ module YMDP
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
module YRB
|
35
|
-
module Support
|
34
|
+
module YRB #:nodoc:
|
35
|
+
module Support #:nodoc:
|
36
36
|
FILENAME_REGEXP = /(.*)_(..-..)\.pres$/
|
37
37
|
|
38
38
|
def language_path(lang)
|
39
|
-
"#{
|
39
|
+
"#{base_path}/app/assets/yrb/#{lang}"
|
40
40
|
end
|
41
41
|
|
42
42
|
def base_filename(path)
|
@@ -58,8 +58,8 @@ module YMDP
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
module Translator
|
62
|
-
module Support
|
61
|
+
module Translator #:nodoc:
|
62
|
+
module Support #:nodoc:
|
63
63
|
# Mapping of the way Yahoo! Mail represents country codes with the way Google Translate does.
|
64
64
|
#
|
65
65
|
# The key is the Yahoo! Mail representation, and the value is the code Google Translate would expect.
|
@@ -87,13 +87,10 @@ module YMDP
|
|
87
87
|
}
|
88
88
|
end
|
89
89
|
|
90
|
-
#
|
91
90
|
# Finds English language translation keys which have not been translated
|
92
91
|
# and translates them through Google Translate.
|
93
92
|
#
|
94
|
-
class Base
|
95
|
-
include YMDP::FileSupport
|
96
|
-
extend YMDP::FileSupport
|
93
|
+
class Base < YMDP::Base
|
97
94
|
include YMDP::Translator::Support
|
98
95
|
|
99
96
|
def self.original_translations
|
@@ -108,10 +105,14 @@ module YMDP
|
|
108
105
|
raise "Define in child"
|
109
106
|
end
|
110
107
|
|
108
|
+
def self.language_path(lang)
|
109
|
+
raise "Define in child"
|
110
|
+
end
|
111
|
+
|
111
112
|
def self.translate
|
112
113
|
Timer.new(:title => "YMDP").time do
|
113
114
|
original_translations.each do |path|
|
114
|
-
puts "Processing #{display_path(path)}"
|
115
|
+
$stdout.puts "Processing #{display_path(path)}"
|
115
116
|
template.new(path).copy
|
116
117
|
end
|
117
118
|
end
|
@@ -127,14 +128,12 @@ module YMDP
|
|
127
128
|
@filename = base_filename(path)
|
128
129
|
end
|
129
130
|
|
130
|
-
def
|
131
|
-
|
131
|
+
def language(path)
|
132
|
+
raise "Define in child"
|
132
133
|
end
|
133
134
|
|
134
|
-
def
|
135
|
-
|
136
|
-
lang !~ /^en/
|
137
|
-
end
|
135
|
+
def copy
|
136
|
+
copy_lines_to_all_locales
|
138
137
|
end
|
139
138
|
|
140
139
|
def non_us_locales
|
@@ -156,9 +155,9 @@ module YMDP
|
|
156
155
|
|
157
156
|
def write_content(destination, content)
|
158
157
|
unless content.blank?
|
159
|
-
puts "Writing to #{display_path(destination)}"
|
160
|
-
puts content
|
161
|
-
puts
|
158
|
+
$stdout.puts "Writing to #{display_path(destination)}"
|
159
|
+
$stdout.puts content
|
160
|
+
$stdout.puts
|
162
161
|
File.open(destination, "a") do |f|
|
163
162
|
f.puts
|
164
163
|
f.puts new_translation_message
|
@@ -185,11 +184,11 @@ module YMDP
|
|
185
184
|
|
186
185
|
def each_line
|
187
186
|
output = []
|
188
|
-
File.
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
187
|
+
@lines ||= File.readlines(path)
|
188
|
+
|
189
|
+
@lines.each do |line|
|
190
|
+
new_line = yield line
|
191
|
+
output << new_line
|
193
192
|
end
|
194
193
|
output.flatten.join("\n")
|
195
194
|
end
|
@@ -204,10 +203,6 @@ module YMDP
|
|
204
203
|
@all_keys
|
205
204
|
end
|
206
205
|
|
207
|
-
def self.all_source_files
|
208
|
-
raise "Define in child"
|
209
|
-
end
|
210
|
-
|
211
206
|
def parse_template(p)
|
212
207
|
raise "Define in child"
|
213
208
|
end
|
@@ -225,9 +220,13 @@ module YMDP
|
|
225
220
|
end
|
226
221
|
end
|
227
222
|
|
223
|
+
def key_is_new?(k, lang)
|
224
|
+
k && !all_keys(lang).has_key?(k)
|
225
|
+
end
|
226
|
+
|
228
227
|
def translate_new_key(line, lang)
|
229
228
|
k, v = key_and_value_from_line(line)
|
230
|
-
if k
|
229
|
+
if key_is_new?(k, lang)
|
231
230
|
format(k, translate(v, lang))
|
232
231
|
else
|
233
232
|
nil
|
@@ -242,9 +241,11 @@ module YMDP
|
|
242
241
|
end
|
243
242
|
|
244
243
|
def pre_process(value, lang)
|
245
|
-
|
244
|
+
vars = []
|
245
|
+
index = 0
|
246
|
+
while value =~ /(\{\d+\})/
|
246
247
|
vars << $1
|
247
|
-
value.sub!(/(\{\
|
248
|
+
value.sub!(/(\{\d+\})/, "[#{index}]")
|
248
249
|
index += 1
|
249
250
|
end
|
250
251
|
value
|
@@ -276,7 +277,7 @@ module YMDP
|
|
276
277
|
|
277
278
|
while value =~ /\[(\d)\]/
|
278
279
|
index = $1.to_i
|
279
|
-
value.sub!(/\[#{index}\]/,
|
280
|
+
value.sub!(/\[#{index}\]/, "{#{index}}")
|
280
281
|
end
|
281
282
|
|
282
283
|
value.gsub!(/\((0)\)/, "{0}")
|
@@ -301,7 +302,7 @@ module YMDP
|
|
301
302
|
end
|
302
303
|
|
303
304
|
# Usage:
|
304
|
-
# YMDP::Translator::Yaml.new().
|
305
|
+
# YMDP::Translator::Yaml.new().copy
|
305
306
|
#
|
306
307
|
class Yaml < Base
|
307
308
|
include YMDP::Yaml::Support
|
@@ -341,7 +342,7 @@ module YMDP
|
|
341
342
|
end
|
342
343
|
|
343
344
|
# Usage:
|
344
|
-
# YMDP::Translator::YRB.new().
|
345
|
+
# YMDP::Translator::YRB.new().copy
|
345
346
|
#
|
346
347
|
class YRB < Base
|
347
348
|
include YMDP::YRB::Support
|
@@ -360,7 +361,7 @@ module YMDP
|
|
360
361
|
end
|
361
362
|
|
362
363
|
def parse_template(p)
|
363
|
-
YMDP::Template::YRB.new(:file => p, :domain => "staging").to_hash
|
364
|
+
YMDP::Compiler::Template::YRB.new(:file => p, :domain => "staging").to_hash
|
364
365
|
end
|
365
366
|
|
366
367
|
def format(key, value)
|
@@ -1,5 +1,381 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "ApplicationView" do
|
4
|
+
before(:each) do
|
5
|
+
@assets_directory = "/om/assets/abcdefg_1"
|
6
|
+
@view = YMDP::View.new(@assets_directory)
|
7
|
+
stub_io
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "languages" do
|
11
|
+
it "should return supported languages" do
|
12
|
+
Dir.stub!(:[]).and_return(["yrb/en-US", "yrb/de-DE", "yrb/es-ES"])
|
13
|
+
@view.supported_languages.should == ["en-US", "de-DE", "es-ES"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise an error if en-US doesn't exist" do
|
17
|
+
Dir.stub!(:[]).and_return(["yrb/de-DE", "yrb/es-ES"])
|
18
|
+
lambda {
|
19
|
+
@view.supported_languages
|
20
|
+
}.should raise_error("Default YRB key en-US not found")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return english languages" do
|
24
|
+
Dir.stub!(:[]).and_return(["yrb/en-US", "yrb/de-DE", "yrb/es-ES", "en-SG"])
|
25
|
+
@view.english_languages.should == ["en-US", "en-SG"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "javascript_include" do
|
30
|
+
describe "local JavaScript" do
|
31
|
+
it "should include local JavaScript asset" do
|
32
|
+
filename = "application.js"
|
33
|
+
@view.javascript_include(filename).should == "<script src='#{@assets_directory}/javascripts/#{filename}' type='text/javascript' charset='utf-8'></script>"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should append .js to local JavaScript filename" do
|
37
|
+
pending
|
38
|
+
filename = "application"
|
39
|
+
@view.javascript_include(filename).should == "<script src='#{@assets_directory}/javascripts/#{filename}.js' type='text/javascript' charset='utf-8'></script>"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "external JavaScript" do
|
44
|
+
it "should include external JavaScript assets" do
|
45
|
+
filename = "http://www.site.com/application.js"
|
46
|
+
@view.javascript_include(filename).should == "<script src='#{filename}' type='text/javascript' charset='utf-8'></script>"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should append .js to external JavaScript filename" do
|
50
|
+
pending
|
51
|
+
filename = "http://www.site.com/application"
|
52
|
+
@view.javascript_include(filename).should == "<script src='#{filename}.js' type='text/javascript' charset='utf-8'></script>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should include firebug lite" do
|
57
|
+
@view.include_firebug_lite.should == "<script src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js' type='text/javascript' charset='utf-8'></script>"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "render" do
|
62
|
+
before(:each) do
|
63
|
+
@processed_template = "processed template"
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ":partial" do
|
67
|
+
describe "single" do
|
68
|
+
describe "Haml" do
|
69
|
+
it "should render a partial if a Haml file exists in app/views" do
|
70
|
+
File.stub!(:exists?).with(/app\/views\/_application.html.haml$/).and_return(true)
|
71
|
+
@view.stub!(:process_haml).and_return(@processed_template)
|
72
|
+
@view.render(:partial => 'application').should == @processed_template
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should render a partial if a Haml file exists in app/views/shared" do
|
76
|
+
File.stub!(:exists?).with(/app\/views\/shared\/_application.html.haml$/).and_return(true)
|
77
|
+
@view.stub!(:process_haml).and_return(@processed_template)
|
78
|
+
@view.render(:partial => 'application').should == @processed_template
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "HTML" do
|
83
|
+
it "should render a partial if an HTML file exists in app/views" do
|
84
|
+
File.stub!(:exists?).with(/app\/views\/_application.html$/).and_return(true)
|
85
|
+
@view.stub!(:process_template).and_return(@processed_template)
|
86
|
+
@view.render(:partial => 'application').should == @processed_template
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should render a partial if an HTML file exists in app/views/shared" do
|
90
|
+
File.stub!(:exists?).with(/app\/views\/shared\/_application.html$/).and_return(true)
|
91
|
+
@view.stub!(:process_template).and_return(@processed_template)
|
92
|
+
@view.render(:partial => 'application').should == @processed_template
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "ERB" do
|
97
|
+
it "should render a partial if an ERB file exists in app/views" do
|
98
|
+
File.stub!(:exists?).with(/app\/views\/_application.html.erb$/).and_return(true)
|
99
|
+
@view.stub!(:process_template).and_return(@processed_template)
|
100
|
+
@view.render(:partial => 'application').should == @processed_template
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should render a partial if an ERB file exists in app/views/shared" do
|
104
|
+
File.stub!(:exists?).with(/app\/views\/shared\/_application.html.erb$/).and_return(true)
|
105
|
+
@view.stub!(:process_template).and_return(@processed_template)
|
106
|
+
@view.render(:partial => 'application').should == @processed_template
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
4
110
|
|
111
|
+
describe "multiple" do
|
112
|
+
describe "Haml" do
|
113
|
+
it "should render multiple partials" do
|
114
|
+
File.stub!(:exists?).with(/app\/views\/_application.html.haml$/).and_return(true)
|
115
|
+
File.stub!(:exists?).with(/app\/views\/_sidebar.html.haml$/).and_return(true)
|
116
|
+
|
117
|
+
@application_haml = "application haml"
|
118
|
+
@sidebar_haml = "sidebar haml"
|
119
|
+
|
120
|
+
@application_file = mock('file', :read => @application_haml)
|
121
|
+
@sidebar_file = mock('file', :read => @sidebar_haml)
|
122
|
+
|
123
|
+
File.stub!(:open).with(/_application.html.haml$/, anything).and_yield(@application_file)
|
124
|
+
File.stub!(:open).with(/_sidebar.html.haml$/, anything).and_yield(@sidebar_file)
|
125
|
+
|
126
|
+
@view.stub!(:process_haml).and_return("application", "sidebar")
|
127
|
+
|
128
|
+
@view.render(:partial => ['application', 'sidebar']).should == "application\nsidebar"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "ERB" do
|
133
|
+
it "should render multiple partials" do
|
134
|
+
File.stub!(:exists?).with(/app\/views\/_application.html.erb$/).and_return(true)
|
135
|
+
File.stub!(:exists?).with(/app\/views\/_sidebar.html.erb$/).and_return(true)
|
136
|
+
|
137
|
+
@application_template = "application erb"
|
138
|
+
@sidebar_template = "sidebar erb"
|
139
|
+
|
140
|
+
@application_file = mock('file', :read => @application_template)
|
141
|
+
@sidebar_file = mock('file', :read => @sidebar_template)
|
142
|
+
|
143
|
+
File.stub!(:open).with(/_application.html.erb$/, anything).and_yield(@application_file)
|
144
|
+
File.stub!(:open).with(/_sidebar.html.erb$/, anything).and_yield(@sidebar_file)
|
145
|
+
|
146
|
+
@view.stub!(:process_template).and_return("application", "sidebar")
|
147
|
+
|
148
|
+
@view.render(:partial => ['application', 'sidebar']).should == "application\nsidebar"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "HTML" do
|
153
|
+
it "should render multiple partials" do
|
154
|
+
File.stub!(:exists?).with(/app\/views\/_application.html$/).and_return(true)
|
155
|
+
File.stub!(:exists?).with(/app\/views\/_sidebar.html$/).and_return(true)
|
156
|
+
|
157
|
+
@application_template = "application html"
|
158
|
+
@sidebar_template = "sidebar html"
|
159
|
+
|
160
|
+
@application_file = mock('file', :read => @application_template)
|
161
|
+
@sidebar_file = mock('file', :read => @sidebar_template)
|
162
|
+
|
163
|
+
File.stub!(:open).with(/_application.html$/, anything).and_yield(@application_file)
|
164
|
+
File.stub!(:open).with(/_sidebar.html$/, anything).and_yield(@sidebar_file)
|
165
|
+
|
166
|
+
@view.stub!(:process_template).and_return("application", "sidebar")
|
167
|
+
|
168
|
+
@view.render(:partial => ['application', 'sidebar']).should == "application\nsidebar"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should raise an error if partial can't be found" do
|
174
|
+
File.stub!(:exists?).and_return(false)
|
175
|
+
lambda {
|
176
|
+
@view.render(:partial => 'application')
|
177
|
+
}.should raise_error("Could not find partial: application")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe ":javascript" do
|
182
|
+
before(:each) do
|
183
|
+
|
184
|
+
@config = mock('config', :compress_embedded_js? => false, :validate_embedded_js? => false)
|
185
|
+
reset_constant(:CONFIG, @config)
|
186
|
+
|
187
|
+
@compressed_template = "compressed template"
|
188
|
+
@processed_script = "<script type='text/javascript'>\n#{@processed_template}\n</script>"
|
189
|
+
@compressed_script = "<script type='text/javascript'>\n#{@compressed_template}\n</script>"
|
190
|
+
YMDP::Compressor::JavaScript.stub!(:compress).and_return(@compressed_template)
|
191
|
+
YMDP::Validator::JavaScript.stub!(:validate)
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "single" do
|
195
|
+
before(:each) do
|
196
|
+
File.stub!(:exists?).and_return(true)
|
197
|
+
@view.stub(:process_template).and_return(@processed_template)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should render a compressed partial" do
|
201
|
+
@config.stub!(:compress_embedded_js?).and_return(true)
|
202
|
+
@view.render(:javascript => 'application').should == @compressed_script
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should render an uncompressed partial" do
|
206
|
+
@config.stub!(:compress_embedded_js?).and_return(false)
|
207
|
+
@view.render(:javascript => 'application').should == @processed_script
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should render compressed without tags" do
|
211
|
+
@config.stub!(:compress_embedded_js?).and_return(true)
|
212
|
+
@view.render(:javascript => 'application', :tags => false).should == @compressed_template
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should render uncompressed without tags" do
|
216
|
+
@config.stub!(:compress_embedded_js?).and_return(false)
|
217
|
+
@view.render(:javascript => 'application', :tags => false).should == @processed_template
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should validate with config true" do
|
221
|
+
@config.stub!(:validate_embedded_js?).and_return(true)
|
222
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/application.js").and_return(true)
|
223
|
+
YMDP::Validator::JavaScript.should_receive(:validate)
|
224
|
+
@view.render(:javascript => 'application')
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should not validate with config false" do
|
228
|
+
@config.stub!(:validate_embedded_js?).and_return(true)
|
229
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/application.js").and_return(false)
|
230
|
+
YMDP::Validator::JavaScript.should_not_receive(:validate)
|
231
|
+
@view.render(:javascript => 'application')
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should not validate if file exists and config true" do
|
235
|
+
@config.stub!(:validate_embedded_js?).and_return(false)
|
236
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/application.js").and_return(true)
|
237
|
+
YMDP::Validator::JavaScript.should_not_receive(:validate)
|
238
|
+
@view.render(:javascript => 'application')
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should not validate if file exists and config false" do
|
242
|
+
@config.stub!(:validate_embedded_js?).and_return(false)
|
243
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/application.js").and_return(true)
|
244
|
+
YMDP::Validator::JavaScript.should_not_receive(:validate)
|
245
|
+
@view.render(:javascript => 'application')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "multiple" do
|
250
|
+
before(:each) do
|
251
|
+
File.stub!(:exists?).with(/app\/javascripts\/application.js$/).and_return(true)
|
252
|
+
File.stub!(:exists?).with(/app\/javascripts\/sidebar.js$/).and_return(true)
|
253
|
+
|
254
|
+
@application_template = "application js"
|
255
|
+
@sidebar_template = "sidebar js"
|
256
|
+
|
257
|
+
@application_file = mock('file', :read => @application_template)
|
258
|
+
@sidebar_file = mock('file', :read => @sidebar_template)
|
259
|
+
|
260
|
+
File.stub!(:open).with(/application.js$/, anything).and_yield(@application_file)
|
261
|
+
File.stub!(:open).with(/sidebar.js$/, anything).and_yield(@sidebar_file)
|
262
|
+
|
263
|
+
@view.stub!(:process_template).and_return("application", "sidebar")
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should render multiple partials" do
|
267
|
+
@view.render(:javascript => ['application', 'sidebar']).should == "<script type='text/javascript'>\napplication\nsidebar\n</script>"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should render multiple partials without tags" do
|
271
|
+
@view.render(:javascript => ['application', 'sidebar'], :tags => false).should == "application\nsidebar"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should render multiple partials to a filename" do
|
275
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/javascripts.js")
|
276
|
+
@view.render(:javascript => ['application', 'sidebar'], :filename => 'javascripts')
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should not raise an error if partial can't be found" do
|
281
|
+
File.stub!(:exists?).and_return(false)
|
282
|
+
lambda {
|
283
|
+
@view.render(:javascript => 'application')
|
284
|
+
}.should_not raise_error
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should return blank string if partial can't be found" do
|
288
|
+
File.stub!(:exists?).and_return(false)
|
289
|
+
lambda {
|
290
|
+
@view.render(:javascript => 'application').should == ""
|
291
|
+
}.should_not raise_error
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe ":stylesheet" do
|
296
|
+
before(:each) do
|
297
|
+
@config = mock('config', :compress_css? => false)
|
298
|
+
reset_constant(:CONFIG, @config)
|
299
|
+
|
300
|
+
@compressed_template = "compressed template"
|
301
|
+
@processed_script = "<style type='text/css'>\n#{@processed_template}\n</style>"
|
302
|
+
@compressed_script = "<style type='text/css'>\n#{@compressed_template}\n</style>"
|
303
|
+
YMDP::Compressor::Stylesheet.stub!(:compress).and_return(@compressed_template)
|
304
|
+
YMDP::Validator::Stylesheet.stub!(:validate).and_return(true)
|
305
|
+
end
|
306
|
+
|
307
|
+
describe "single" do
|
308
|
+
before(:each) do
|
309
|
+
File.stub!(:exists?).and_return(true)
|
310
|
+
@view.stub(:process_template).and_return(@processed_template)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should render a compressed partial" do
|
314
|
+
@config.stub!(:compress_css?).and_return(true)
|
315
|
+
@view.render(:stylesheet => 'application').should == @compressed_script
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should render an uncompressed partial" do
|
319
|
+
@config.stub!(:compress_css?).and_return(false)
|
320
|
+
@view.render(:stylesheet => 'application').should == @processed_script
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should render compressed without tags" do
|
324
|
+
@config.stub!(:compress_css?).and_return(true)
|
325
|
+
@view.render(:stylesheet => 'application', :tags => false).should == @compressed_template
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should render uncompressed without tags" do
|
329
|
+
@config.stub!(:compress_css?).and_return(false)
|
330
|
+
@view.render(:stylesheet => 'application', :tags => false).should == @processed_template
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe "multiple" do
|
335
|
+
before(:each) do
|
336
|
+
File.stub!(:exists?).with(/app\/stylesheets\/application.css$/).and_return(true)
|
337
|
+
File.stub!(:exists?).with(/app\/stylesheets\/sidebar.css$/).and_return(true)
|
338
|
+
|
339
|
+
@application_template = "application css"
|
340
|
+
@sidebar_template = "sidebar css"
|
341
|
+
|
342
|
+
@application_file = mock('file', :read => @application_template)
|
343
|
+
@sidebar_file = mock('file', :read => @sidebar_template)
|
344
|
+
|
345
|
+
File.stub!(:open).with(/application.css$/, anything).and_yield(@application_file)
|
346
|
+
File.stub!(:open).with(/sidebar.css$/, anything).and_yield(@sidebar_file)
|
347
|
+
|
348
|
+
@view.stub!(:process_template).and_return("application", "sidebar")
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should render multiple partials" do
|
352
|
+
@view.render(:stylesheet => ['application', 'sidebar']).should == "<style type='text/css'>\napplication\nsidebar\n</style>"
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should render multiple partials without tags" do
|
356
|
+
@view.render(:stylesheet => ['application', 'sidebar'], :tags => false).should == "application\nsidebar"
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should render multiple partials to a filename" do
|
360
|
+
F.should_receive(:save_to_file).with(anything, "./tmp/stylesheets.css")
|
361
|
+
@view.render(:stylesheet => ['application', 'sidebar'], :filename => 'stylesheets')
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should not raise an error if partial can't be found" do
|
366
|
+
File.stub!(:exists?).and_return(false)
|
367
|
+
lambda {
|
368
|
+
@view.render(:stylesheet => 'application')
|
369
|
+
}.should_not raise_error
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should return blank string if partial can't be found" do
|
373
|
+
File.stub!(:exists?).and_return(false)
|
374
|
+
lambda {
|
375
|
+
@view.render(:stylesheet => 'application').should == ""
|
376
|
+
}.should_not raise_error
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
5
381
|
end
|