ymdp 0.1.3.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,5 +10,7 @@ require 'ymdp'
10
10
  require 'spec'
11
11
  require 'spec/autorun'
12
12
 
13
+ require 'stubs'
14
+
13
15
  Spec::Runner.configure do |config|
14
- end
16
+ end
@@ -0,0 +1,42 @@
1
+
2
+ def stub_screen_io
3
+ $stdout.stub!(:puts)
4
+ $stdout.stub!(:print)
5
+ end
6
+
7
+ def stub_file_io(unprocessed_file="")
8
+ @file ||= mock('file').as_null_object
9
+ @file.stub!(:read).and_return(unprocessed_file)
10
+
11
+ File.stub!(:exists?).and_return(false)
12
+ File.stub!(:open).and_yield(@file)
13
+ end
14
+
15
+ def stub_file_utils
16
+ FileUtils.stub!(:rm)
17
+ FileUtils.stub!(:rm_rf)
18
+ FileUtils.stub!(:cp_r)
19
+ FileUtils.stub!(:mkdir_p)
20
+ F.stub!(:concat_files)
21
+ end
22
+
23
+ def stub_yaml(output_hash={})
24
+ YAML.stub!(:load_file).and_return(output_hash)
25
+ end
26
+
27
+ def stub_erb(processed_file="")
28
+ @erb ||= mock('erb').as_null_object
29
+ @erb.stub!(:result).and_return(processed_file)
30
+ ERB.stub!(:new).and_return(@erb)
31
+ end
32
+
33
+ def stub_git_helper
34
+ @git_helper = mock('git_helper').as_null_object
35
+ GitHelper.stub!(:new).and_return(@git_helper)
36
+ end
37
+
38
+ def stub_timer
39
+ @timer = mock('timer').as_null_object
40
+ @timer.stub!(:time).and_yield
41
+ Timer.stub!(:new).and_return(@timer)
42
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ymdp}
8
- s.version = "0.1.3.2"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeff Coleman"]
@@ -88,8 +88,12 @@ Gem::Specification.new do |s|
88
88
  "lib/new_application/ymdp",
89
89
  "lib/ymdp.rb",
90
90
  "lib/ymdp/asset_tag_helper.rb",
91
+ "lib/ymdp/commands/build.rb",
91
92
  "lib/ymdp/commands/generate.rb",
92
- "lib/ymdp/compiler/compiler.rb",
93
+ "lib/ymdp/compiler/base.rb",
94
+ "lib/ymdp/compiler/domains.rb",
95
+ "lib/ymdp/compiler/git_helper.rb",
96
+ "lib/ymdp/compiler/options.rb",
93
97
  "lib/ymdp/compiler/template.rb",
94
98
  "lib/ymdp/configuration/config.rb",
95
99
  "lib/ymdp/configuration/constants.rb",
@@ -99,18 +103,19 @@ Gem::Specification.new do |s|
99
103
  "lib/ymdp/generator/templates/view.html.haml",
100
104
  "lib/ymdp/helpers.rb",
101
105
  "lib/ymdp/processor/compressor.rb",
106
+ "lib/ymdp/processor/form_post.rb",
102
107
  "lib/ymdp/processor/processor.rb",
103
108
  "lib/ymdp/processor/validator.rb",
109
+ "lib/ymdp/processor/w3c.rb",
104
110
  "lib/ymdp/support/blank.rb",
105
111
  "lib/ymdp/support/file.rb",
106
- "lib/ymdp/support/form_post.rb",
107
- "lib/ymdp/support/git_helper.rb",
108
- "lib/ymdp/support/w3c.rb",
109
112
  "lib/ymdp/tag_helper.rb",
110
113
  "lib/ymdp/tasks/keys.rake",
111
114
  "lib/ymdp/tasks/ymdp.rake",
112
115
  "lib/ymdp/translator/base.rb",
113
116
  "lib/ymdp/ymdp.rb",
117
+ "spec/compiler_spec.rb",
118
+ "spec/compiler_template_spec.rb",
114
119
  "spec/configuration_spec.rb",
115
120
  "spec/data/Rakefile",
116
121
  "spec/data/VERSION",
@@ -174,8 +179,10 @@ Gem::Specification.new do |s|
174
179
  "spec/data/script/ymdt",
175
180
  "spec/data/script/ymdt.old",
176
181
  "spec/data/script/yuicompressor-2.4.2.jar",
182
+ "spec/domains_spec.rb",
177
183
  "spec/spec.opts",
178
184
  "spec/spec_helper.rb",
185
+ "spec/stubs.rb",
179
186
  "spec/translator_spec.rb",
180
187
  "spec/ymdp_spec.rb",
181
188
  "ymdp.gemspec"
@@ -186,11 +193,15 @@ Gem::Specification.new do |s|
186
193
  s.rubygems_version = %q{1.3.5}
187
194
  s.summary = %q{Framework for developing applications in the Yahoo! Mail Development Platform}
188
195
  s.test_files = [
189
- "spec/configuration_spec.rb",
196
+ "spec/compiler_spec.rb",
197
+ "spec/compiler_template_spec.rb",
198
+ "spec/configuration_spec.rb",
190
199
  "spec/data/app/helpers/application_helper.rb",
191
200
  "spec/data/config/constants.rb",
192
201
  "spec/data/lib/init.rb",
202
+ "spec/domains_spec.rb",
193
203
  "spec/spec_helper.rb",
204
+ "spec/stubs.rb",
194
205
  "spec/translator_spec.rb",
195
206
  "spec/ymdp_spec.rb"
196
207
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ymdp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Coleman
@@ -211,8 +211,12 @@ files:
211
211
  - lib/new_application/ymdp
212
212
  - lib/ymdp.rb
213
213
  - lib/ymdp/asset_tag_helper.rb
214
+ - lib/ymdp/commands/build.rb
214
215
  - lib/ymdp/commands/generate.rb
215
- - lib/ymdp/compiler/compiler.rb
216
+ - lib/ymdp/compiler/base.rb
217
+ - lib/ymdp/compiler/domains.rb
218
+ - lib/ymdp/compiler/git_helper.rb
219
+ - lib/ymdp/compiler/options.rb
216
220
  - lib/ymdp/compiler/template.rb
217
221
  - lib/ymdp/configuration/config.rb
218
222
  - lib/ymdp/configuration/constants.rb
@@ -222,18 +226,19 @@ files:
222
226
  - lib/ymdp/generator/templates/view.html.haml
223
227
  - lib/ymdp/helpers.rb
224
228
  - lib/ymdp/processor/compressor.rb
229
+ - lib/ymdp/processor/form_post.rb
225
230
  - lib/ymdp/processor/processor.rb
226
231
  - lib/ymdp/processor/validator.rb
232
+ - lib/ymdp/processor/w3c.rb
227
233
  - lib/ymdp/support/blank.rb
228
234
  - lib/ymdp/support/file.rb
229
- - lib/ymdp/support/form_post.rb
230
- - lib/ymdp/support/git_helper.rb
231
- - lib/ymdp/support/w3c.rb
232
235
  - lib/ymdp/tag_helper.rb
233
236
  - lib/ymdp/tasks/keys.rake
234
237
  - lib/ymdp/tasks/ymdp.rake
235
238
  - lib/ymdp/translator/base.rb
236
239
  - lib/ymdp/ymdp.rb
240
+ - spec/compiler_spec.rb
241
+ - spec/compiler_template_spec.rb
237
242
  - spec/configuration_spec.rb
238
243
  - spec/data/Rakefile
239
244
  - spec/data/VERSION
@@ -297,8 +302,10 @@ files:
297
302
  - spec/data/script/ymdt
298
303
  - spec/data/script/ymdt.old
299
304
  - spec/data/script/yuicompressor-2.4.2.jar
305
+ - spec/domains_spec.rb
300
306
  - spec/spec.opts
301
307
  - spec/spec_helper.rb
308
+ - spec/stubs.rb
302
309
  - spec/translator_spec.rb
303
310
  - spec/ymdp_spec.rb
304
311
  - ymdp.gemspec
@@ -331,10 +338,14 @@ signing_key:
331
338
  specification_version: 3
332
339
  summary: Framework for developing applications in the Yahoo! Mail Development Platform
333
340
  test_files:
341
+ - spec/compiler_spec.rb
342
+ - spec/compiler_template_spec.rb
334
343
  - spec/configuration_spec.rb
335
344
  - spec/data/app/helpers/application_helper.rb
336
345
  - spec/data/config/constants.rb
337
346
  - spec/data/lib/init.rb
347
+ - spec/domains_spec.rb
338
348
  - spec/spec_helper.rb
349
+ - spec/stubs.rb
339
350
  - spec/translator_spec.rb
340
351
  - spec/ymdp_spec.rb
@@ -1,278 +0,0 @@
1
- module YMDP
2
- module Compiler
3
- # Command-line options processor for Compiler module.
4
- #
5
- class Options
6
- # Parse command line options into an options hash.
7
- #
8
- def self.parse
9
- options = {
10
- :commit => false,
11
- :branch => "master"
12
- }
13
- OptionParser.new do |opts|
14
- options[:commit] = false
15
- options[:verbose] = CONFIG.verbose?
16
- opts.banner = "Usage: build.rb [options]"
17
-
18
- opts.on("-d", "--domain [domain]", "Force Domain") do |v|
19
- options[:domain] = v
20
- end
21
- opts.on("-b", "--branch [branch]", "Current Branch") do |v|
22
- options[:branch] = v
23
- end
24
- opts.on("-m", "--message [message]", "Commit Message") do |v|
25
- options[:commit] = true
26
- options[:message] = v
27
- end
28
- opts.on("-n", "--no-commit", "Don't Commit") do |v|
29
- options[:commit] = false
30
- end
31
- opts.on("-v", "--verbose", "Verbose (show all file writes)") do |v|
32
- options[:verbose] = true
33
- end
34
- opts.on("-r", "--rake [task]", "Execute Rake task") do |v|
35
- options[:rake] = v
36
- end
37
- opts.on("-c", "--compress", "Compress JavaScript and CSS") do |v|
38
- options[:compress] = v
39
- end
40
- end.parse!
41
-
42
- options
43
- end
44
- end
45
-
46
- # Covers all the domains and the actions that are taken on all domains at once.
47
- #
48
- class Domains
49
- attr_accessor :git, :git_hash, :message, :domains, :options
50
-
51
- def initialize(options=nil)
52
- @options = options || Compiler::Options.parse
53
- @domains = @options[:domain] || all_domains
54
- @domains = @domains.to_a
55
- @message = @options[:message]
56
-
57
- commit
58
- end
59
-
60
- # Returns all domains.
61
- #
62
- def all_domains
63
- SERVERS.servers.keys
64
- end
65
-
66
- # Commit to git and store the hash of the commit.
67
- #
68
- def commit
69
- @git = GitHelper.new
70
- if options[:commit]
71
- git.do_commit(@message)
72
- end
73
- @git_hash = git.get_hash(options[:branch])
74
- end
75
-
76
- # Compile the source code for all domains into their usable destination files.
77
- #
78
- def compile
79
- Timer.new(:title => "YMDP").time do
80
- clean_tmp_dir do
81
- process_domains
82
- end
83
- end
84
- rescue StandardError => e
85
- puts e.message
86
- puts e.backtrace
87
- end
88
-
89
- # Process source code for each domain in turn.
90
- #
91
- def process_domains
92
- domains.each do |domain|
93
- compiler = Compiler::Base.new(domain, git_hash, options)
94
-
95
- compiler.clean_domain
96
-
97
- ["views", "assets"].each do |dir|
98
- compiler.process("#{BASE_PATH}/app/#{dir}/")
99
- end
100
- end
101
-
102
- if options[:rake]
103
- system "rake #{options[:rake]}"
104
- end
105
- end
106
-
107
- # Perform a block, starting with a clean 'tmp' directory and ending with one.
108
- #
109
- def clean_tmp_dir
110
- system "rm -rf #{TMP_DIR}"
111
- system "mkdir #{TMP_DIR}"
112
- yield
113
- system "rm -rf #{TMP_DIR}"
114
- system "mkdir #{TMP_DIR}"
115
- end
116
- end
117
-
118
- # Compiles the source code for an individual domain.
119
- #
120
- # Usage:
121
- #
122
- # @compiler = Compiler::Base.new('staging', 'asdfh23rh2fas')
123
- #
124
- # You can then compile the domain:
125
- #
126
- # @compiler.build
127
- #
128
- class Base
129
- attr_accessor :domain, :git_hash, :options
130
-
131
- # A TemplateCompiler instance covers a single domain, handling all the processing necessary to
132
- # convert the application source code into usable destination files ready for upload.
133
- #
134
- def initialize(domain, git_hash, options)
135
- @domain = domain
136
- @git_hash = git_hash
137
- @options = options
138
- end
139
-
140
- # Do all the processing necessary to convert the application source code into usable destination files ready for upload to the server:
141
- #
142
- # - create server directory if necessary,
143
- # - for each file in the source path, build the file, and
144
- # - copy the images from the source to the destination directory.
145
- #
146
- def process(path)
147
- puts "Processing #{path} for #{domain}"
148
- create_directory("servers/#{domain}")
149
- process_all_files(path)
150
- process_all_translations
151
- copy_images
152
- end
153
-
154
- # Process all code files (HTML and JavaScript) into usable, complete HTML files.
155
- #
156
- def process_all_files(path)
157
- Dir["#{path}**/*"].each do |f|
158
- build_file(f)
159
- end
160
- end
161
-
162
- # Build this file if it's either:
163
- # - a view, but not a partial or layout, or
164
- # - a JavaScript file.
165
- #
166
- def build_file(file)
167
- params = {
168
- :file => file, :domain => domain, :git_hash => git_hash, :message => options[:message], :verbose => options[:verbose]
169
- }
170
- if build?(file)
171
- if file =~ /(\.haml|\.erb)$/
172
- YMDP::Template::View.new(params).build
173
- elsif file =~ /\.js$/
174
- YMDP::Template::JavaScript.new(params).build
175
- end
176
- end
177
- end
178
-
179
- # Convert all YRB translation files from YRB ".pres" format into a single JSON file per language.
180
- #
181
- def process_all_translations
182
- puts "Processing ./app/assets/yrb/ for #{domain}"
183
- YMDP::Base.supported_languages.each do |lang|
184
- process_each_yrb(lang)
185
- end
186
- end
187
-
188
- # Convert the YRB translation files of a single language for this domain into a single JSON file.
189
- #
190
- def process_each_yrb(lang)
191
- tmp_file = "#{TMP_DIR}/keys_#{lang}.pres"
192
-
193
- # Concatenate together all the YRB ".pres" files for this language into one file in the tmp dir.
194
- #
195
- Dir["#{BASE_PATH}/app/assets/yrb/#{lang}/*"].each do |path|
196
- system "cat #{path} >> #{tmp_file}"
197
- end
198
-
199
- yrb = YMDP::Template::YRB.new(:file => tmp_file, :domain => domain)
200
- yrb.build
201
- yrb.validate if CONFIG.validate_json_assets?
202
- system "rm #{tmp_file}"
203
- end
204
-
205
- # Creates a fresh destination directory structure for the code to be compiled into.
206
- #
207
- def clean_domain
208
- dir = "#{YMDP_ROOT}/servers/#{domain}"
209
- system "rm -rf #{dir}/views"
210
- system "rm -rf #{dir}/assets/javascripts"
211
- system "rm -rf #{dir}/assets/stylesheets"
212
- system "rm -rf #{dir}/assets/yrb"
213
- system "rm -rf #{TMP_DIR}/"
214
- system "mkdir #{TMP_DIR}"
215
- end
216
-
217
- # Format text in a standard way for output to the screen.
218
- #
219
- def log(text)
220
- "#{Time.now.to_s} #{text}"
221
- end
222
-
223
- # If this directory doesn't exist, create it and print that it's being created.
224
- #
225
- def create_directory(path)
226
- dest = destination(path)
227
-
228
- unless File.exists?("#{BASE_PATH}/#{path}")
229
- puts " create #{path}"
230
- FileUtils.mkdir_p "#{BASE_PATH}/#{path}"
231
- end
232
- end
233
-
234
- # Convert a file's path from its source to its destination.
235
- #
236
- # The source directory is in the 'app' directory.
237
- #
238
- # The destination directory is made from the 'servers' root and the domain name.
239
- #
240
- # For example:
241
- # - ./servers/staging
242
- # - ./servers/alpha
243
- #
244
- def destination(path)
245
- destination = path.dup
246
- destination.gsub!("#{YMDP_ROOT}/app", "#{YMDP_ROOT}/servers/#{domain}")
247
- end
248
-
249
- # Images don't require any processing, just copy them over into this domain's assets directory.
250
- #
251
- def copy_images
252
- if options[:verbose]
253
- puts log("Moving images into #{YMDP_ROOT}/servers/#{domain}/assets/images...")
254
- end
255
- system "rm -rf #{YMDP_ROOT}/servers/#{domain}/assets/images"
256
- system "cp -r #{YMDP_ROOT}/app/assets/images #{YMDP_ROOT}/servers/#{domain}/assets"
257
- end
258
-
259
- # A filename beginning with an underscore is a partial.
260
- #
261
- def partial?(file)
262
- file.split("/").last =~ /^_/
263
- end
264
-
265
- # A file in the layouts directory is a layout.
266
- #
267
- def layout?(file)
268
- file =~ /\/app\/views\/layouts\//
269
- end
270
-
271
- # Build if it's not a partial and not a layout.
272
- #
273
- def build?(file)
274
- !partial?(file) && !layout?(file)
275
- end
276
- end
277
- end
278
- end