ymdp_generator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/support/file.rb +54 -0
- data/lib/view.rb +226 -0
- data/lib/ymdp_generator.rb +61 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/ymdp_generator_spec.rb +499 -0
- data/ymdp_generator.gemspec +57 -0
- metadata +78 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jeff Coleman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= ymdp_generator
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Jeff Coleman. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ymdp_generator"
|
8
|
+
gem.summary = %Q{Generates new views and assets for YMDP applications.}
|
9
|
+
gem.description = %Q{Generates new views, JavaScripts, stylesheets and translation assets for Yahoo! Mail Development Platform applications.}
|
10
|
+
gem.email = "progressions@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/progressions/ymdp_generator"
|
12
|
+
gem.authors = ["Jeff Coleman"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.6"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
spec.spec_opts = ['-c']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "ymdp_generator #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/support/file.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module YMDP
|
2
|
+
module FileSupport
|
3
|
+
def confirm_overwrite(path)
|
4
|
+
if File.exists?(path)
|
5
|
+
$stdout.puts "File exists: #{File.expand_path(path)}"
|
6
|
+
$stdout.print " overwrite? (y/n)"
|
7
|
+
answer = $stdin.gets
|
8
|
+
|
9
|
+
answer =~ /^y/i
|
10
|
+
else
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# friendlier display of paths
|
16
|
+
def display_path(path)
|
17
|
+
path = File.expand_path(path)
|
18
|
+
path.gsub(BASE_PATH, "")
|
19
|
+
end
|
20
|
+
|
21
|
+
# saves the output string to the filename given
|
22
|
+
#
|
23
|
+
def save_to_file(output, filename)
|
24
|
+
unless File.exists?(filename)
|
25
|
+
File.open(filename, "w") do |w|
|
26
|
+
w.write(output)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# given a path and line number, returns the line and two lines previous
|
32
|
+
#
|
33
|
+
def get_line_from_file(path, line_number)
|
34
|
+
line_number = line_number.to_i
|
35
|
+
output = ""
|
36
|
+
lines = []
|
37
|
+
|
38
|
+
File.open(path) do |f|
|
39
|
+
lines = f.readlines
|
40
|
+
end
|
41
|
+
|
42
|
+
output += "\n"
|
43
|
+
|
44
|
+
3.times do |i|
|
45
|
+
line = lines[line_number-(3-i)]
|
46
|
+
output += line if line
|
47
|
+
end
|
48
|
+
|
49
|
+
output += "\n"
|
50
|
+
|
51
|
+
output
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/view.rb
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'support/file'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Generates new files for a new view.
|
5
|
+
#
|
6
|
+
# See YMDP::Generator::Base for more.
|
7
|
+
#
|
8
|
+
module YMDP
|
9
|
+
module Generator
|
10
|
+
# Pieces of code which will be added to existing files by the Modifications class.
|
11
|
+
#
|
12
|
+
module Snippets
|
13
|
+
# Creates a method which will launch the new view from within any other view.
|
14
|
+
#
|
15
|
+
def launcher_method(view)
|
16
|
+
view = view.downcase
|
17
|
+
class_name = view.capitalize
|
18
|
+
<<-OUTPUT
|
19
|
+
|
20
|
+
Launcher.launch#{class_name} = function() {
|
21
|
+
Launcher.launchTab("#{view}", "#{class_name}");
|
22
|
+
};
|
23
|
+
OUTPUT
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Templates
|
28
|
+
# Basic processing of templates (ERB by default).
|
29
|
+
#
|
30
|
+
class Base
|
31
|
+
include YMDP::FileSupport
|
32
|
+
|
33
|
+
attr_accessor :view, :template_path, :application_path
|
34
|
+
|
35
|
+
# View name should be a single word that's valid as a filename.
|
36
|
+
#
|
37
|
+
def initialize(view, params={})
|
38
|
+
@view = view
|
39
|
+
@template_path = params[:template_path]
|
40
|
+
@application_path = params[:application_path]
|
41
|
+
|
42
|
+
raise ArgumentError.new("template_path is required") unless @template_path
|
43
|
+
raise ArgumentError.new("application_path is required") unless @application_path
|
44
|
+
end
|
45
|
+
|
46
|
+
# Write the template to its destination_path after it has been processed.
|
47
|
+
#
|
48
|
+
def generate
|
49
|
+
write_processed_template
|
50
|
+
end
|
51
|
+
|
52
|
+
# PROCESSING
|
53
|
+
|
54
|
+
# Process this template. By default templates are processed with ERB.
|
55
|
+
#
|
56
|
+
# Override this in a child to change this behavior.
|
57
|
+
#
|
58
|
+
# _content_ should be a string, which contains the unprocessed source code
|
59
|
+
# of the file.
|
60
|
+
#
|
61
|
+
def process_template(content)
|
62
|
+
ERB.new(content, 0, "%<>").result(binding)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return the content of this file after it has been processed.
|
66
|
+
#
|
67
|
+
# Read the unprocessed content from the source_path and pass it to
|
68
|
+
# process_template and return the result.
|
69
|
+
#
|
70
|
+
def processed_template
|
71
|
+
unprocessed_content = ""
|
72
|
+
File.open(source_path) do |f|
|
73
|
+
unprocessed_content = f.read
|
74
|
+
end
|
75
|
+
process_template(unprocessed_content)
|
76
|
+
end
|
77
|
+
|
78
|
+
# FILE I/O
|
79
|
+
|
80
|
+
# Write the result of processed_template to the destination path.
|
81
|
+
#
|
82
|
+
def write_processed_template
|
83
|
+
if confirm_overwrite(destination_path)
|
84
|
+
append_to_file(destination_path, processed_template)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Append the content to a file and log that it's happening.
|
89
|
+
#
|
90
|
+
def append_to_file(file, content)
|
91
|
+
File.open(file, "a") do |f|
|
92
|
+
$stdout.puts " #{display_path(file)} writing . . ."
|
93
|
+
f.puts content
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# PATH HELPERS
|
98
|
+
|
99
|
+
# Generate the destination path for this file from its destination directory
|
100
|
+
# and its filename.
|
101
|
+
#
|
102
|
+
def destination_path
|
103
|
+
"#{destination_dir}/#{destination_filename}"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Generate the source path from the template directory and the source filename.
|
107
|
+
#
|
108
|
+
def source_path
|
109
|
+
"#{template_path}/#{source_filename}"
|
110
|
+
end
|
111
|
+
|
112
|
+
# The source filename for the blank template file.
|
113
|
+
#
|
114
|
+
def source_filename
|
115
|
+
raise "Define in child"
|
116
|
+
end
|
117
|
+
|
118
|
+
# The destination filename based on the view name of this object.
|
119
|
+
#
|
120
|
+
def destination_filename
|
121
|
+
raise "Define in child"
|
122
|
+
end
|
123
|
+
|
124
|
+
# The destination directory based on the application_path and type of this object.
|
125
|
+
#
|
126
|
+
def destination_dir
|
127
|
+
raise "Define in child"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# A View is an HTML file, located at "#{BASE_PATH}/app/views/_view_.html.haml".
|
132
|
+
#
|
133
|
+
# The source template for new view files is located at "generator/templates/view.html.haml".
|
134
|
+
#
|
135
|
+
# ERB is also supported, but is not recommended.
|
136
|
+
#
|
137
|
+
class View < Base
|
138
|
+
def source_filename
|
139
|
+
"view.html.haml"
|
140
|
+
end
|
141
|
+
|
142
|
+
def destination_filename
|
143
|
+
"#{view}.html.haml"
|
144
|
+
end
|
145
|
+
|
146
|
+
def destination_dir
|
147
|
+
"#{application_path}/views"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# JavaScripts are located at "#{BASE_PATH}/app/javascripts/_view_.js".
|
152
|
+
#
|
153
|
+
# The source templates are found at "generator/templates/javascript.js"
|
154
|
+
#
|
155
|
+
class JavaScript < Base
|
156
|
+
def source_filename
|
157
|
+
"javascript.js"
|
158
|
+
end
|
159
|
+
|
160
|
+
def destination_filename
|
161
|
+
"#{view}.js"
|
162
|
+
end
|
163
|
+
|
164
|
+
def destination_dir
|
165
|
+
"#{application_path}/javascripts"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Stylesheets are located at "#{BASE_PATH}/app/stylesheets/_view_.css".
|
170
|
+
#
|
171
|
+
# The source templates are found at "generator/templates/stylesheet.css"
|
172
|
+
#
|
173
|
+
class Stylesheet < Base
|
174
|
+
def source_filename
|
175
|
+
"stylesheet.css"
|
176
|
+
end
|
177
|
+
|
178
|
+
def destination_filename
|
179
|
+
"#{view}.css"
|
180
|
+
end
|
181
|
+
|
182
|
+
def destination_dir
|
183
|
+
"#{application_path}/stylesheets"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# JavaScripts are located at "#{BASE_PATH}/app/assets/yrb/en-US/new_view_en-US.pres".
|
188
|
+
#
|
189
|
+
# The source templates are found at "generator/templates/translation.pres"
|
190
|
+
#
|
191
|
+
class Translation < Base
|
192
|
+
def source_filename
|
193
|
+
"translation.pres"
|
194
|
+
end
|
195
|
+
|
196
|
+
def destination_filename
|
197
|
+
"new_#{view}_en-US.pres"
|
198
|
+
end
|
199
|
+
|
200
|
+
def destination_dir
|
201
|
+
"#{application_path}/assets/yrb/en-US"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Modifications cover anything that needs to be done to existing files when a
|
206
|
+
# new view is added.
|
207
|
+
#
|
208
|
+
class Modifications < Base
|
209
|
+
include Snippets
|
210
|
+
|
211
|
+
def generate
|
212
|
+
content = launcher_method(view)
|
213
|
+
append_to_file(destination_path, content)
|
214
|
+
end
|
215
|
+
|
216
|
+
def destination_filename
|
217
|
+
"launcher.js"
|
218
|
+
end
|
219
|
+
|
220
|
+
def destination_dir
|
221
|
+
"#{application_path}/javascripts"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'view'
|
2
|
+
|
3
|
+
# Generates a new view, with all the associated files relating to that view.
|
4
|
+
#
|
5
|
+
# Creates the following files:
|
6
|
+
#
|
7
|
+
# 1. View, at "#{BASE_PATH}/app/assets/views/_view_.html.haml"
|
8
|
+
#
|
9
|
+
# A Haml file with a single line of boilerplate copy.
|
10
|
+
#
|
11
|
+
# 2. JavaScript file, at "#{BASE_PATH}/app/javascripts/_view_.js"
|
12
|
+
#
|
13
|
+
# A complete set of the basic JavaScript functions needed to execute a page.
|
14
|
+
#
|
15
|
+
# 3. Stylesheet, at "#{BASE_PATH}/app/stylesheets/_view_.css"
|
16
|
+
#
|
17
|
+
# A blank CSS file.
|
18
|
+
#
|
19
|
+
# 4. Translation keys, at "#{BASE_PATH}/app/assets/yrb/en-US/new_view_en-US.pres"
|
20
|
+
#
|
21
|
+
# A new translation file, with a heading and a subhead key.
|
22
|
+
#
|
23
|
+
# 5. Modification
|
24
|
+
#
|
25
|
+
# Currently the only modification to any existing files is the creation of a 'launcher' method
|
26
|
+
# in "#{BASE_PATH}/app/javascripts/launcher.js"
|
27
|
+
#
|
28
|
+
# 6. Translation of new keys into all languages.
|
29
|
+
#
|
30
|
+
# Translates the new keys into all languages and creates associated ".pres" files in the
|
31
|
+
# correct subdirectories.
|
32
|
+
#
|
33
|
+
module YMDP
|
34
|
+
module Generator
|
35
|
+
# Parses the command as the first parameter and generates the appropriate files.
|
36
|
+
#
|
37
|
+
class Base
|
38
|
+
attr_accessor :template_path, :application_path
|
39
|
+
|
40
|
+
def initialize(params={})
|
41
|
+
@template_path = params[:template_path]
|
42
|
+
@application_path = params[:application_path]
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate(view)
|
46
|
+
$stdout.puts "Create a new view: #{view}"
|
47
|
+
|
48
|
+
p = {
|
49
|
+
:template_path => template_path,
|
50
|
+
:application_path => application_path
|
51
|
+
}
|
52
|
+
|
53
|
+
YMDP::Generator::Templates::View.new(view, p).generate
|
54
|
+
YMDP::Generator::Templates::JavaScript.new(view, p).generate
|
55
|
+
YMDP::Generator::Templates::Stylesheet.new(view, p).generate
|
56
|
+
YMDP::Generator::Templates::Translation.new(view, p).generate
|
57
|
+
YMDP::Generator::Templates::Modifications.new(view, p).generate
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
BASE_PATH = File.dirname(__FILE__)
|
5
|
+
|
6
|
+
require 'ymdp_generator'
|
7
|
+
require 'spec'
|
8
|
+
require 'spec/autorun'
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,499 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Generate" do
|
4
|
+
before(:each) do
|
5
|
+
# stub screen I/O
|
6
|
+
$stdout.stub!(:puts)
|
7
|
+
$stdout.stub!(:print)
|
8
|
+
|
9
|
+
@template_path = "templates"
|
10
|
+
@application_path = "app"
|
11
|
+
@p = {
|
12
|
+
:template_path => @template_path,
|
13
|
+
:application_path => @application_path
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Base" do
|
18
|
+
before(:each) do
|
19
|
+
@generator = mock('generator', :generate => true)
|
20
|
+
YMDP::Generator::Templates::View.stub!(:new).and_return(@generator)
|
21
|
+
YMDP::Generator::Templates::JavaScript.stub!(:new).and_return(@generator)
|
22
|
+
YMDP::Generator::Templates::Stylesheet.stub!(:new).and_return(@generator)
|
23
|
+
YMDP::Generator::Templates::Translation.stub!(:new).and_return(@generator)
|
24
|
+
YMDP::Generator::Templates::Modifications.stub!(:new).and_return(@generator)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "new view" do
|
28
|
+
before(:each) do
|
29
|
+
@base = YMDP::Generator::Base.new(@p)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "instantiation" do
|
33
|
+
it "should create a new instance" do
|
34
|
+
@base.should_not be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set template_path" do
|
38
|
+
@base.template_path.should == @template_path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should generate a new view" do
|
43
|
+
YMDP::Generator::Templates::View.should_receive(:new).with("funk", @p)
|
44
|
+
@base.generate("funk")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should generate a new JavaScript" do
|
48
|
+
YMDP::Generator::Templates::JavaScript.should_receive(:new).with("funk", @p)
|
49
|
+
@base.generate("funk")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should generate a new stylesheet" do
|
53
|
+
YMDP::Generator::Templates::Stylesheet.should_receive(:new).with("funk", @p)
|
54
|
+
@base.generate("funk")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should generate a new translation" do
|
58
|
+
YMDP::Generator::Templates::Translation.should_receive(:new).with("funk", @p)
|
59
|
+
@base.generate("funk")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should generate a new set of modifications" do
|
63
|
+
YMDP::Generator::Templates::Modifications.should_receive(:new).with("funk", @p)
|
64
|
+
@base.generate("funk")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def stub_file_io(unprocessed_file)
|
70
|
+
# stub file I/O
|
71
|
+
@file ||= mock('file').as_null_object
|
72
|
+
@file.stub!(:read).and_return(unprocessed_file)
|
73
|
+
|
74
|
+
File.stub!(:exists?).and_return(false)
|
75
|
+
File.stub!(:open).and_yield(@file)
|
76
|
+
end
|
77
|
+
|
78
|
+
def stub_erb(processed_file)
|
79
|
+
# stub ERB
|
80
|
+
@erb ||= mock('erb').as_null_object
|
81
|
+
@erb.stub!(:result).and_return(processed_file)
|
82
|
+
ERB.stub!(:new).and_return(@erb)
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "subclasses" do
|
86
|
+
before(:each) do
|
87
|
+
@view = "funk"
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "View" do
|
91
|
+
before(:each) do
|
92
|
+
@view_regex = /app\/views\/#{@view}\.html\.haml/
|
93
|
+
|
94
|
+
# before and after
|
95
|
+
@unprocessed_file = "This is the <%= @view %> view."
|
96
|
+
@processed_file = "This is the #{@view} view."
|
97
|
+
|
98
|
+
@source_filename = "#{@template_path}/view.html.haml"
|
99
|
+
|
100
|
+
stub_file_io(@unprocessed_file)
|
101
|
+
stub_erb(@processed_file)
|
102
|
+
|
103
|
+
@generator = YMDP::Generator::Templates::View.new(@view, @p)
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "instantiation" do
|
107
|
+
it "should make a new instance" do
|
108
|
+
@generator.should_not be_nil
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should set view" do
|
112
|
+
@generator.view.should == @view
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should set template_path" do
|
116
|
+
@generator.template_path.should == @template_path
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise error without template_path" do
|
120
|
+
lambda {
|
121
|
+
YMDP::Generator::Templates::View.new(@view, :destination_dir => "destination")
|
122
|
+
}.should raise_error(ArgumentError)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should raise error without destination_dir" do
|
126
|
+
lambda {
|
127
|
+
YMDP::Generator::Templates::View.new(@view, :template_path => "templates")
|
128
|
+
}.should raise_error(ArgumentError)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "generation" do
|
133
|
+
it "should read the source file" do
|
134
|
+
File.should_receive(:open).with(@source_filename)
|
135
|
+
@generator.generate
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "file exists" do
|
139
|
+
before(:each) do
|
140
|
+
$stdin.stub!(:gets).and_return("y")
|
141
|
+
File.stub!(:exists?).with(@view_regex).and_return(true)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should confirm the file exists" do
|
145
|
+
File.should_receive(:exists?).with(@view_regex).and_return(false)
|
146
|
+
@generator.generate
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should prompt to overwrite if the file exists" do
|
150
|
+
$stdout.should_receive(:print).with(/overwrite\?/)
|
151
|
+
@generator.generate
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should overwrite if the answer is no" do
|
155
|
+
File.should_receive(:open).with(@view_regex, "a")
|
156
|
+
@generator.generate
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should not overwrite if the answer is no" do
|
160
|
+
$stdin.stub!(:gets).and_return("n")
|
161
|
+
File.should_not_receive(:open).with(@view_regex, "a")
|
162
|
+
@generator.generate
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "processing" do
|
167
|
+
it "should instantiate ERB" do
|
168
|
+
ERB.should_receive(:new).with(@unprocessed_file, anything, anything).and_return(@erb)
|
169
|
+
@generator.generate
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should get result from ERB" do
|
173
|
+
@erb.should_receive(:result)
|
174
|
+
@generator.generate
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should write the processed result" do
|
178
|
+
@file.should_receive(:puts).with(@processed_file)
|
179
|
+
@generator.generate
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should write the file" do
|
184
|
+
File.should_receive(:open).with(@view_regex, "a")
|
185
|
+
@generator.generate
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "JavaScript" do
|
191
|
+
before(:each) do
|
192
|
+
@view_regex = /app\/javascripts\/#{@view}\.js/
|
193
|
+
|
194
|
+
# before and after
|
195
|
+
@unprocessed_file = "This is the <%= @view %> JavaScript."
|
196
|
+
@processed_file = "This is the #{@view} JavaScript."
|
197
|
+
|
198
|
+
@source_filename = "#{@template_path}/javascript.js"
|
199
|
+
|
200
|
+
stub_file_io(@unprocessed_file)
|
201
|
+
stub_erb(@processed_file)
|
202
|
+
|
203
|
+
@generator = YMDP::Generator::Templates::JavaScript.new(@view, @p)
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "instantiation" do
|
207
|
+
it "should make a new instance" do
|
208
|
+
@generator.should_not be_nil
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should set view" do
|
212
|
+
@generator.view.should == @view
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should set template_path" do
|
216
|
+
@generator.template_path.should == @template_path
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "generation" do
|
221
|
+
it "should read the source file" do
|
222
|
+
File.should_receive(:open).with(@source_filename)
|
223
|
+
@generator.generate
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "file exists" do
|
227
|
+
before(:each) do
|
228
|
+
$stdin.stub!(:gets).and_return("y")
|
229
|
+
File.stub!(:exists?).with(@view_regex).and_return(true)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should confirm the file exists" do
|
233
|
+
File.should_receive(:exists?).with(@view_regex).and_return(false)
|
234
|
+
@generator.generate
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should prompt to overwrite if the file exists" do
|
238
|
+
$stdout.should_receive(:print).with(/overwrite\?/)
|
239
|
+
@generator.generate
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should overwrite if the answer is no" do
|
243
|
+
File.should_receive(:open).with(@view_regex, "a")
|
244
|
+
@generator.generate
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should not overwrite if the answer is no" do
|
248
|
+
$stdin.stub!(:gets).and_return("n")
|
249
|
+
File.should_not_receive(:open).with(@view_regex, "a")
|
250
|
+
@generator.generate
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "processing" do
|
255
|
+
it "should instantiate ERB" do
|
256
|
+
ERB.should_receive(:new).with(@unprocessed_file, anything, anything).and_return(@erb)
|
257
|
+
@generator.generate
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should get result from ERB" do
|
261
|
+
@erb.should_receive(:result)
|
262
|
+
@generator.generate
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should write the processed result" do
|
266
|
+
@file.should_receive(:puts).with(@processed_file)
|
267
|
+
@generator.generate
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should write the file" do
|
272
|
+
File.should_receive(:open).with(@view_regex, "a")
|
273
|
+
@generator.generate
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe "Stylesheet" do
|
279
|
+
before(:each) do
|
280
|
+
@view_regex = /app\/stylesheets\/#{@view}\.css/
|
281
|
+
|
282
|
+
# before and after
|
283
|
+
@unprocessed_file = "This is the <%= @view %> stylesheet."
|
284
|
+
@processed_file = "This is the #{@view} stylesheet."
|
285
|
+
|
286
|
+
@source_filename = "#{@template_path}/stylesheet.css"
|
287
|
+
|
288
|
+
stub_file_io(@unprocessed_file)
|
289
|
+
stub_erb(@processed_file)
|
290
|
+
|
291
|
+
@generator = YMDP::Generator::Templates::Stylesheet.new(@view, @p)
|
292
|
+
end
|
293
|
+
|
294
|
+
describe "instantiation" do
|
295
|
+
it "should make a new instance" do
|
296
|
+
@generator.should_not be_nil
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should set view" do
|
300
|
+
@generator.view.should == @view
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should set template_path" do
|
304
|
+
@generator.template_path.should == @template_path
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "generation" do
|
309
|
+
it "should read the source file" do
|
310
|
+
File.should_receive(:open).with(@source_filename)
|
311
|
+
@generator.generate
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "file exists" do
|
315
|
+
before(:each) do
|
316
|
+
$stdin.stub!(:gets).and_return("y")
|
317
|
+
File.stub!(:exists?).with(@view_regex).and_return(true)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should confirm the file exists" do
|
321
|
+
File.should_receive(:exists?).with(@view_regex).and_return(false)
|
322
|
+
@generator.generate
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should prompt to overwrite if the file exists" do
|
326
|
+
$stdout.should_receive(:print).with(/overwrite\?/)
|
327
|
+
@generator.generate
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should overwrite if the answer is no" do
|
331
|
+
File.should_receive(:open).with(@view_regex, "a")
|
332
|
+
@generator.generate
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should not overwrite if the answer is no" do
|
336
|
+
$stdin.stub!(:gets).and_return("n")
|
337
|
+
File.should_not_receive(:open).with(@view_regex, "a")
|
338
|
+
@generator.generate
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "processing" do
|
343
|
+
it "should instantiate ERB" do
|
344
|
+
ERB.should_receive(:new).with(@unprocessed_file, anything, anything).and_return(@erb)
|
345
|
+
@generator.generate
|
346
|
+
end
|
347
|
+
|
348
|
+
it "should get result from ERB" do
|
349
|
+
@erb.should_receive(:result)
|
350
|
+
@generator.generate
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should write the processed result" do
|
354
|
+
@file.should_receive(:puts).with(@processed_file)
|
355
|
+
@generator.generate
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should write the file" do
|
360
|
+
File.should_receive(:open).with(@view_regex, "a")
|
361
|
+
@generator.generate
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
describe "Translation" do
|
367
|
+
before(:each) do
|
368
|
+
@view_regex = /app\/assets\/yrb\/en-US\/new_#{@view}_en-US\.pres/
|
369
|
+
|
370
|
+
# before and after
|
371
|
+
@unprocessed_file = "This is the <%= @view %> translation."
|
372
|
+
@processed_file = "This is the #{@view} translation."
|
373
|
+
|
374
|
+
@source_filename = "#{@template_path}/translation.pres"
|
375
|
+
|
376
|
+
stub_file_io(@unprocessed_file)
|
377
|
+
stub_erb(@processed_file)
|
378
|
+
|
379
|
+
@generator = YMDP::Generator::Templates::Translation.new(@view, @p)
|
380
|
+
end
|
381
|
+
|
382
|
+
describe "instantiation" do
|
383
|
+
it "should make a new instance" do
|
384
|
+
@generator.should_not be_nil
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should set view" do
|
388
|
+
@generator.view.should == @view
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should set template_path" do
|
392
|
+
@generator.template_path.should == @template_path
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "generation" do
|
397
|
+
it "should read the source file" do
|
398
|
+
File.should_receive(:open).with(@source_filename)
|
399
|
+
@generator.generate
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "file exists" do
|
403
|
+
before(:each) do
|
404
|
+
$stdin.stub!(:gets).and_return("y")
|
405
|
+
File.stub!(:exists?).with(@view_regex).and_return(true)
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should confirm the file exists" do
|
409
|
+
File.should_receive(:exists?).with(@view_regex).and_return(false)
|
410
|
+
@generator.generate
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should prompt to overwrite if the file exists" do
|
414
|
+
$stdout.should_receive(:print).with(/overwrite\?/)
|
415
|
+
@generator.generate
|
416
|
+
end
|
417
|
+
|
418
|
+
it "should overwrite if the answer is no" do
|
419
|
+
File.should_receive(:open).with(@view_regex, "a")
|
420
|
+
@generator.generate
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should not overwrite if the answer is no" do
|
424
|
+
$stdin.stub!(:gets).and_return("n")
|
425
|
+
File.should_not_receive(:open).with(@view_regex, "a")
|
426
|
+
@generator.generate
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
describe "processing" do
|
431
|
+
it "should instantiate ERB" do
|
432
|
+
ERB.should_receive(:new).with(@unprocessed_file, anything, anything).and_return(@erb)
|
433
|
+
@generator.generate
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should get result from ERB" do
|
437
|
+
@erb.should_receive(:result)
|
438
|
+
@generator.generate
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should write the processed result" do
|
442
|
+
@file.should_receive(:puts).with(@processed_file)
|
443
|
+
@generator.generate
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should write the file" do
|
448
|
+
File.should_receive(:open).with(@view_regex, "a")
|
449
|
+
@generator.generate
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
describe "Modifications" do
|
455
|
+
before(:each) do
|
456
|
+
@view_regex = /app\/javascripts\/#{@view}\.js/
|
457
|
+
|
458
|
+
# before and after
|
459
|
+
@unprocessed_file = "This is the <%= @view %> JavaScript."
|
460
|
+
@processed_file = "Launcher.launch#{@view.capitalize}"
|
461
|
+
|
462
|
+
@source_filename = "app/javascripts/launcher.js"
|
463
|
+
|
464
|
+
stub_file_io(@unprocessed_file)
|
465
|
+
stub_erb(@processed_file)
|
466
|
+
|
467
|
+
@generator = YMDP::Generator::Templates::Modifications.new(@view, @p)
|
468
|
+
end
|
469
|
+
|
470
|
+
describe "instantiation" do
|
471
|
+
it "should make a new instance" do
|
472
|
+
@generator.should_not be_nil
|
473
|
+
end
|
474
|
+
|
475
|
+
it "should set view" do
|
476
|
+
@generator.view.should == @view
|
477
|
+
end
|
478
|
+
|
479
|
+
it "should set template_path" do
|
480
|
+
@generator.template_path.should == @template_path
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
describe "generation" do
|
485
|
+
it "should read the source file" do
|
486
|
+
File.should_receive(:open).with(/#{@source_filename}$/, "a")
|
487
|
+
@generator.generate
|
488
|
+
end
|
489
|
+
|
490
|
+
describe "processing" do
|
491
|
+
it "should write the processed result" do
|
492
|
+
@file.should_receive(:puts).with(/#{@processed_file}/)
|
493
|
+
@generator.generate
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ymdp_generator}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeff Coleman"]
|
12
|
+
s.date = %q{2010-01-14}
|
13
|
+
s.description = %q{Generates new views, JavaScripts, stylesheets and translation assets for Yahoo! Mail Development Platform applications.}
|
14
|
+
s.email = %q{progressions@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/support/file.rb",
|
27
|
+
"lib/view.rb",
|
28
|
+
"lib/ymdp_generator.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"spec/ymdp_generator_spec.rb",
|
32
|
+
"ymdp_generator.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/progressions/ymdp_generator}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
38
|
+
s.summary = %q{Generates new views and assets for YMDP applications.}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/spec_helper.rb",
|
41
|
+
"spec/ymdp_generator_spec.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.6"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 1.2.6"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.6"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ymdp_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-14 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.6
|
24
|
+
version:
|
25
|
+
description: Generates new views, JavaScripts, stylesheets and translation assets for Yahoo! Mail Development Platform applications.
|
26
|
+
email: progressions@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/support/file.rb
|
42
|
+
- lib/view.rb
|
43
|
+
- lib/ymdp_generator.rb
|
44
|
+
- spec/spec.opts
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
- spec/ymdp_generator_spec.rb
|
47
|
+
- ymdp_generator.gemspec
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/progressions/ymdp_generator
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Generates new views and assets for YMDP applications.
|
76
|
+
test_files:
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/ymdp_generator_spec.rb
|