ymdp 0.1.3.1 → 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ begin
21
21
  gem.add_development_dependency "bundler", ">= 0"
22
22
  gem.add_development_dependency "timer", ">= 0"
23
23
  gem.add_development_dependency "serenity", ">= 0"
24
+ gem.add_development_dependency "ymdp_generator", ">= 0"
24
25
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
26
  end
26
27
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3.1
1
+ 0.1.3.2
@@ -1,3 +1,10 @@
1
- require 'generator/base'
1
+ require 'translator/base'
2
2
 
3
- YMDP::Generator::Base.generate(ARGV)
3
+ if ARGV[0] == "view"
4
+ p = {
5
+ :template_path => File.join(File.dirname(__FILE__), "..", "generator", "templates"),
6
+ :application_path => APPLICATION_PATH
7
+ }
8
+ YMDP::Generator::Base.new(p).generate(ARGV[1])
9
+ YMDP::Translator::YRB.translate
10
+ end
@@ -1,3 +1,17 @@
1
+ # Process source files into usable code.
2
+ #
3
+ # Source files can be HTML, Haml, ERB, JavaScript, or CSS files.
4
+ #
5
+ # Files with an extension of ".haml" will be processed with Haml, all others will
6
+ # use ERB.
7
+ #
8
+ # Usage:
9
+ #
10
+ # YMDP::Template::View.new(params).build
11
+ # YMDP::Template::JavaScript.new(params).build
12
+ #
13
+ # See YMDP::Template::Base#initialize for details on params.
14
+ #
1
15
  module YMDP
2
16
  module Template
3
17
  # Compiles a single file in a single domain, processing its Haml or ERB and turning
@@ -161,6 +175,14 @@ module YMDP
161
175
  end
162
176
 
163
177
  class View < Base
178
+ # TODO: Refactor this. Right now it includes all the YMDP::Base and other helper files
179
+ # into the same namespace where we're processing the templates. It does this so it can
180
+ # send its 'binding' into the ERB or Haml template and the template will be able to
181
+ # process methods like "render :partial => 'sidebar'" and so on.
182
+ #
183
+ # All the methods which are meant to be run from inside a view need to be refactored into
184
+ # their own class, which can be sent into the template as a binding.
185
+ #
164
186
  include ActionView::Helpers::TagHelper
165
187
 
166
188
  begin
@@ -207,49 +229,72 @@ module YMDP
207
229
  Haml::Engine.new(template, options).render(self)
208
230
  end
209
231
 
232
+ # Write this template with the application layout applied.
233
+ #
234
+ # Validate the resulting HTML file if that option is turned on.
235
+ #
210
236
  def write_template(result)
211
237
  write_template_with_layout(result)
212
238
  YMDP::Validator::HTML.validate(destination_path) if CONFIG.validate_html?
213
239
  end
214
240
  end
215
241
 
242
+ # Process templates for JavaScript files.
243
+ #
244
+ # JavaScript files support ERB tags.
245
+ #
216
246
  class JavaScript < View
217
- def compress_js(filename)
218
- if compress_js_assets?
219
- validate_filename = "#{filename}.min"
220
- YMDP::Compressor::JavaScript.compress(filename)
221
- end
222
- end
223
-
247
+ # Write the processed template without any layout.
248
+ #
249
+ # Run the JavaScript compressor on the file if that option is turned on.
250
+ #
224
251
  def write_template(result)
225
252
  filename = @file.split("/").last
226
253
  tmp_filename = "./tmp/#{filename}"
227
254
  save_to_file(result, tmp_filename)
228
- result = YMDP::Compressor::JavaScript.compress(tmp_filename) || result
255
+ result = YMDP::Compressor::JavaScript.compress(tmp_filename) if CONFIG.compress_embedded_js?
229
256
  write_template_without_layout(result)
230
257
  end
231
258
  end
232
259
 
260
+ # Process Yahoo! Resource Bundle format translation files.
261
+ #
262
+ # Convert them to a hash and write the hash to a JSON file.
263
+ #
264
+ # Each language can have as many YRB translation files (with an extension of ".pres")
265
+ # as necessary. The files are concatenated together and translated into a single JSON file
266
+ # for each language.
267
+ #
233
268
  class YRB < Base
269
+ # Base directory for translations for this domain.
270
+ #
234
271
  def directory
235
272
  directory = "#{BASE_PATH}/servers/#{@domain}/assets/yrb"
236
273
  FileUtils.mkdir_p(directory)
237
274
  directory
238
275
  end
239
276
 
277
+ # The destination of the compiled JSON file.
278
+ #
240
279
  def destination_path
241
280
  filename = convert_filename(@file.split("/").last)
242
281
  "#{directory}/#{filename}"
243
282
  end
244
283
 
284
+ # JSON values of the compiled translations.
285
+ #
245
286
  def to_json
246
287
  processed_template
247
288
  end
248
289
 
290
+ # Turn it back into a hash.
291
+ #
249
292
  def to_hash
250
293
  JSON.parse(to_json)
251
294
  end
252
295
 
296
+ # Convert the hash to Yaml if you should want to do that.
297
+ #
253
298
  def to_yaml
254
299
  h = {}
255
300
  to_hash.each do |k,v|
@@ -259,32 +304,56 @@ module YMDP
259
304
  h.to_yaml
260
305
  end
261
306
 
307
+ # This function is the file which is written to the destination--in this
308
+ # case, the JSON file.
309
+ #
262
310
  def processed_template
263
311
  super.to_json
264
312
  end
265
313
 
314
+ # Validate the JSON file.
315
+ #
266
316
  def validate
267
317
  YMDP::Validator::JSON.validate(destination_path)
268
318
  end
269
319
 
270
320
  private
271
-
321
+
322
+ # Strip off the ".pres" extension from original YRB files.
323
+ #
272
324
  def base_filename(filename)
273
325
  filename.gsub(/\.pres/, "")
274
326
  end
275
327
 
328
+ # Take the base filename and add the ".json" extension.
329
+ #
276
330
  def convert_filename(filename)
277
331
  "#{base_filename(filename)}.json"
278
332
  end
333
+
334
+ # Is this line a valid comment in YRB?
335
+ def comment?(line)
336
+ line =~ /^[\s]*#/
337
+ end
338
+
339
+ # Is this line valid YRB syntax?
340
+ #
341
+ def key_and_value_from_line(line)
342
+ if line =~ /^([^\=]+)=(.+)/
343
+ return $1, $2.strip
344
+ else
345
+ return nil, nil
346
+ end
347
+ end
279
348
 
349
+ # Parse YRB and add it to a hash. Raise an error if the key already exists in the hash.
350
+ #
280
351
  def process_template(template)
281
352
  @hash = {}
282
353
  lines = template.split("\n")
283
354
  lines.each do |line|
284
- unless line =~ /^[\s]*#/
285
- line =~ /^([^\=]+)=(.+)/
286
- key = $1
287
- value = $2
355
+ unless comment?(line)
356
+ key, value = key_and_value_from_line(line)
288
357
  unless key.blank?
289
358
  if @hash.has_key?(key)
290
359
  puts
@@ -305,6 +374,8 @@ module YMDP
305
374
  @hash
306
375
  end
307
376
 
377
+ # Write JSON file to its destination.
378
+ #
308
379
  def write_template(result)
309
380
  puts destination_path if CONFIG.verbose?
310
381
  write_template_without_layout(result)
@@ -1,5 +1,5 @@
1
1
  YMDP_ROOT = BASE_PATH unless defined?(YMDP_ROOT)
2
2
  TMP_DIR = TMP_PATH unless defined?(TMP_DIR)
3
3
 
4
- CONFIG = YMDP::Configuration::Config.new
5
- SERVERS = YMDP::Configuration::Servers.new
4
+ CONFIG = YMDP::Configuration::Config.new unless defined?(CONFIG)
5
+ SERVERS = YMDP::Configuration::Servers.new unless defined?(SERVERS)
@@ -2,8 +2,8 @@ module YMDP
2
2
  module FileSupport
3
3
  def confirm_overwrite(path)
4
4
  if File.exists?(path)
5
- puts "File exists: #{display_path(path)}"
6
- print " overwrite? (y/n)"
5
+ $stdout.puts "File exists: #{File.expand_path(path)}"
6
+ $stdout.print " overwrite? (y/n)"
7
7
  answer = $stdin.gets
8
8
 
9
9
  answer =~ /^y/i
@@ -3,7 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'mime/types'
5
5
  require 'net/http'
6
- require 'CGI'
6
+ # require 'CGI'
7
7
 
8
8
  class FormField
9
9
  attr_accessor :name, :value
@@ -109,7 +109,7 @@ module YMDP
109
109
  end
110
110
 
111
111
  def self.translate
112
- time do
112
+ Timer.new(:title => "YMDP").time do
113
113
  original_translations.each do |path|
114
114
  puts "Processing #{display_path(path)}"
115
115
  template.new(path).copy
@@ -360,7 +360,7 @@ module YMDP
360
360
  end
361
361
 
362
362
  def parse_template(p)
363
- YRBTemplate.new(p).to_hash
363
+ YMDP::Template::YRB.new(:file => p, :domain => "staging").to_hash
364
364
  end
365
365
 
366
366
  def format(key, value)
data/ymdp.gemspec CHANGED
@@ -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.1"
8
+ s.version = "0.1.3.2"
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"]
@@ -93,12 +93,10 @@ Gem::Specification.new do |s|
93
93
  "lib/ymdp/compiler/template.rb",
94
94
  "lib/ymdp/configuration/config.rb",
95
95
  "lib/ymdp/configuration/constants.rb",
96
- "lib/ymdp/generator/base.rb",
97
96
  "lib/ymdp/generator/templates/javascript.js",
98
97
  "lib/ymdp/generator/templates/stylesheet.css",
99
98
  "lib/ymdp/generator/templates/translation.pres",
100
99
  "lib/ymdp/generator/templates/view.html.haml",
101
- "lib/ymdp/generator/view.rb",
102
100
  "lib/ymdp/helpers.rb",
103
101
  "lib/ymdp/processor/compressor.rb",
104
102
  "lib/ymdp/processor/processor.rb",
@@ -213,6 +211,7 @@ Gem::Specification.new do |s|
213
211
  s.add_development_dependency(%q<bundler>, [">= 0"])
214
212
  s.add_development_dependency(%q<timer>, [">= 0"])
215
213
  s.add_development_dependency(%q<serenity>, [">= 0"])
214
+ s.add_development_dependency(%q<ymdp_generator>, [">= 0"])
216
215
  else
217
216
  s.add_dependency(%q<haml>, [">= 0"])
218
217
  s.add_dependency(%q<json>, [">= 0"])
@@ -225,6 +224,7 @@ Gem::Specification.new do |s|
225
224
  s.add_dependency(%q<bundler>, [">= 0"])
226
225
  s.add_dependency(%q<timer>, [">= 0"])
227
226
  s.add_dependency(%q<serenity>, [">= 0"])
227
+ s.add_dependency(%q<ymdp_generator>, [">= 0"])
228
228
  end
229
229
  else
230
230
  s.add_dependency(%q<haml>, [">= 0"])
@@ -238,6 +238,7 @@ Gem::Specification.new do |s|
238
238
  s.add_dependency(%q<bundler>, [">= 0"])
239
239
  s.add_dependency(%q<timer>, [">= 0"])
240
240
  s.add_dependency(%q<serenity>, [">= 0"])
241
+ s.add_dependency(%q<ymdp_generator>, [">= 0"])
241
242
  end
242
243
  end
243
244
 
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.1
4
+ version: 0.1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Coleman
@@ -122,6 +122,16 @@ dependencies:
122
122
  - !ruby/object:Gem::Version
123
123
  version: "0"
124
124
  version:
125
+ - !ruby/object:Gem::Dependency
126
+ name: ymdp_generator
127
+ type: :development
128
+ version_requirement:
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ version:
125
135
  description: Framework for developing applications in the Yahoo! Mail Development Platform.
126
136
  email: progressions@gmail.com
127
137
  executables:
@@ -206,12 +216,10 @@ files:
206
216
  - lib/ymdp/compiler/template.rb
207
217
  - lib/ymdp/configuration/config.rb
208
218
  - lib/ymdp/configuration/constants.rb
209
- - lib/ymdp/generator/base.rb
210
219
  - lib/ymdp/generator/templates/javascript.js
211
220
  - lib/ymdp/generator/templates/stylesheet.css
212
221
  - lib/ymdp/generator/templates/translation.pres
213
222
  - lib/ymdp/generator/templates/view.html.haml
214
- - lib/ymdp/generator/view.rb
215
223
  - lib/ymdp/helpers.rb
216
224
  - lib/ymdp/processor/compressor.rb
217
225
  - lib/ymdp/processor/processor.rb
@@ -1,15 +0,0 @@
1
- require 'generator/view'
2
-
3
- module YMDP
4
- module Generator
5
- class Base
6
- def self.generate(args)
7
- @command = args.shift
8
-
9
- if @command == "view"
10
- YMDP::Generator::View.new(args).generate
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,170 +0,0 @@
1
- require 'support/file'
2
- require 'translator/base'
3
- require 'erb'
4
-
5
- module YMDP
6
- module Generator
7
- module Snippets
8
- def launcher_method(view)
9
- view = view.downcase
10
- class_name = view.capitalize
11
- <<-OUTPUT
12
-
13
- Launcher.launch#{class_name} = function() {
14
- Launcher.launchTab("#{view}", "#{class_name}");
15
- };
16
- OUTPUT
17
- end
18
- end
19
-
20
- module Templates
21
- class Base
22
- include YMDP::FileSupport
23
-
24
- attr_accessor :view
25
-
26
- def initialize(view)
27
- @view = view
28
- end
29
-
30
- def generate
31
- write_processed_template
32
- end
33
-
34
- def template_dir
35
- "#{APPLICATION_PATH}/generator/templates"
36
- end
37
-
38
- def process_template(template)
39
- ERB.new(template, 0, "%<>").result(binding)
40
- end
41
-
42
- def processed_template
43
- result = ""
44
- File.open(full_template_path) do |f|
45
- template = f.read
46
- result = process_template(template)
47
- end
48
- result
49
- end
50
-
51
- def write_processed_template
52
- write_to_file
53
- end
54
-
55
- def destination_path
56
- "#{destination_dir}/#{destination_filename}"
57
- end
58
-
59
- def full_template_path
60
- "#{template_dir}/#{template_filename}"
61
- end
62
-
63
- def write_processed_template
64
- if confirm_overwrite(destination_path)
65
- append_to_file(destination_path, processed_template)
66
- end
67
- end
68
-
69
- def append_to_file(file, content)
70
- File.open(file, "a") do |f|
71
- puts " #{display_path(file)} writing . . ."
72
- f.puts content
73
- end
74
- end
75
- end
76
-
77
- class View < Base
78
- def template_filename
79
- "view.html.haml"
80
- end
81
-
82
- def destination_filename
83
- "#{view}.html.haml"
84
- end
85
-
86
- def destination_dir
87
- "#{BASE_PATH}/app/views"
88
- end
89
- end
90
-
91
- class JavaScript < Base
92
- def template_filename
93
- "javascript.js"
94
- end
95
-
96
- def destination_dir
97
- "#{BASE_PATH}/app/javascripts"
98
- end
99
-
100
- def destination_filename
101
- "#{view}.js"
102
- end
103
- end
104
-
105
- class Stylesheet < Base
106
- def template_filename
107
- "stylesheet.css"
108
- end
109
-
110
- def destination_dir
111
- "#{BASE_PATH}/app/stylesheets"
112
- end
113
-
114
- def destination_filename
115
- "#{view}.css"
116
- end
117
- end
118
-
119
- class Translation < Base
120
- def template_filename
121
- "translation.pres"
122
- end
123
-
124
- def destination_dir
125
- "#{BASE_PATH}/app/assets/yrb/en-US"
126
- end
127
-
128
- def destination_filename
129
- "new_#{view}_en-US.pres"
130
- end
131
- end
132
-
133
- class Modifications < Base
134
- include Snippets
135
-
136
- def generate
137
- content = launcher_method(view)
138
- append_to_file(destination_path, content)
139
- end
140
-
141
- def destination_dir
142
- "#{BASE_PATH}/app/javascripts"
143
- end
144
-
145
- def destination_filename
146
- "launcher.js"
147
- end
148
- end
149
- end
150
-
151
- class View
152
- attr_accessor :view
153
-
154
- def initialize(args)
155
- @view = args.first
156
- end
157
-
158
- def generate
159
- puts "Create a new view: #{view}"
160
-
161
- Templates::View.new(view).generate
162
- Templates::JavaScript.new(view).generate
163
- Templates::Stylesheet.new(view).generate
164
- Templates::Translation.new(view).generate
165
- Templates::Modifications.new(view).generate
166
- YMDP::Translator::YRB.translate
167
- end
168
- end
169
- end
170
- end