architecture-js 0.5.8 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +12 -2
- data/Guardfile +24 -0
- data/VERSION +1 -1
- data/architecture-js.gemspec +11 -6
- data/lib/architecture-js.rb +2 -1
- data/lib/architecture-js/architect.rb +9 -70
- data/lib/architecture-js/blueprint.rb +42 -10
- data/spec/architect_spec.rb +1 -15
- data/spec/architecture-js_spec.rb +5 -3
- data/spec/blueprint_spec.rb +2 -6
- data/spec/fixtures/multiple_templates.blueprint +8 -0
- data/spec/fixtures/myapp.blueprint +2 -0
- data/spec/fixtures/test_template.jst +1 -0
- data/spec/templates_spec.rb +92 -0
- data/templates/templates_file.erb +3 -0
- metadata +25 -7
- data/lib/architecture-js/generator.rb +0 -66
- data/spec/generator_spec.rb +0 -58
- data/templates/blank.js +0 -0
data/Gemfile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
3
|
gem "listen"
|
4
|
+
gem "ejs"
|
4
5
|
gem "jsmin", "~> 1.0.1"
|
5
6
|
|
6
7
|
group :test do
|
7
8
|
gem "simplecov", "~> 0.5.4", :require => false
|
9
|
+
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
|
10
|
+
gem 'guard-rspec'
|
8
11
|
end
|
9
12
|
|
10
13
|
group :development do
|
data/Gemfile.lock
CHANGED
@@ -2,16 +2,22 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
diff-lcs (1.1.3)
|
5
|
+
ejs (1.1.1)
|
5
6
|
ffi (1.0.11)
|
6
7
|
git (1.2.5)
|
7
|
-
|
8
|
+
guard (1.2.1)
|
9
|
+
listen (>= 0.4.2)
|
10
|
+
thor (>= 0.14.6)
|
11
|
+
guard-rspec (1.1.0)
|
12
|
+
guard (>= 1.1)
|
13
|
+
jeweler (1.8.4)
|
8
14
|
bundler (~> 1.0)
|
9
15
|
git (>= 1.2.5)
|
10
16
|
rake
|
11
17
|
rdoc
|
12
18
|
jsmin (1.0.1)
|
13
19
|
json (1.7.3)
|
14
|
-
listen (0.4.
|
20
|
+
listen (0.4.7)
|
15
21
|
rb-fchange (~> 0.0.5)
|
16
22
|
rb-fsevent (~> 0.9.1)
|
17
23
|
rb-inotify (~> 0.8.8)
|
@@ -36,14 +42,18 @@ GEM
|
|
36
42
|
multi_json (~> 1.0.3)
|
37
43
|
simplecov-html (~> 0.5.3)
|
38
44
|
simplecov-html (0.5.3)
|
45
|
+
thor (0.15.4)
|
39
46
|
|
40
47
|
PLATFORMS
|
41
48
|
ruby
|
42
49
|
|
43
50
|
DEPENDENCIES
|
44
51
|
bundler
|
52
|
+
ejs
|
53
|
+
guard-rspec
|
45
54
|
jeweler (~> 1.8.3)
|
46
55
|
jsmin (~> 1.0.1)
|
47
56
|
listen
|
57
|
+
rb-fsevent
|
48
58
|
rspec (~> 2.8.0)
|
49
59
|
simplecov (~> 0.5.4)
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/architecture-js.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "architecture-js"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dayton Nolan"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-07-01"
|
13
13
|
s.description = "Architecture.js helps you generate scaffolding, manage third-party packages, compile, and compress your application."
|
14
14
|
s.email = "daytonn@gmail.com"
|
15
15
|
s.executables = ["architect"]
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"AUTHORS",
|
26
26
|
"Gemfile",
|
27
27
|
"Gemfile.lock",
|
28
|
+
"Guardfile",
|
28
29
|
"HELP",
|
29
30
|
"LICENSE.txt",
|
30
31
|
"README.md",
|
@@ -38,7 +39,6 @@ Gem::Specification.new do |s|
|
|
38
39
|
"lib/architecture-js/architect.rb",
|
39
40
|
"lib/architecture-js/blueprint.rb",
|
40
41
|
"lib/architecture-js/dependencies.rb",
|
41
|
-
"lib/architecture-js/generator.rb",
|
42
42
|
"lib/architecture-js/helpers.rb",
|
43
43
|
"lib/architecture-js/notification.rb",
|
44
44
|
"lib/architecture-js/watcher.rb",
|
@@ -97,27 +97,29 @@ Gem::Specification.new do |s|
|
|
97
97
|
"spec/fixtures/lib1_compressed.js",
|
98
98
|
"spec/fixtures/lib2.js",
|
99
99
|
"spec/fixtures/lib2_compressed.js",
|
100
|
+
"spec/fixtures/multiple_templates.blueprint",
|
100
101
|
"spec/fixtures/myapp.blueprint",
|
101
102
|
"spec/fixtures/src_file.js",
|
102
103
|
"spec/fixtures/templates/env_template.js",
|
103
104
|
"spec/fixtures/templates/test_template_one.js",
|
104
105
|
"spec/fixtures/templates/test_template_two.js",
|
105
106
|
"spec/fixtures/test_blueprint.rb",
|
107
|
+
"spec/fixtures/test_template.jst",
|
106
108
|
"spec/fixtures/test_template_options.js",
|
107
109
|
"spec/fixtures/test_template_two.js",
|
108
110
|
"spec/fixtures/underscore_template.js",
|
109
111
|
"spec/fixtures/update.blueprint",
|
110
112
|
"spec/fixtures/update.js",
|
111
|
-
"spec/generator_spec.rb",
|
112
113
|
"spec/helpers_spec.rb",
|
113
114
|
"spec/notification_spec.rb",
|
114
115
|
"spec/spec_helper.rb",
|
115
|
-
"
|
116
|
+
"spec/templates_spec.rb",
|
117
|
+
"templates/templates_file.erb"
|
116
118
|
]
|
117
119
|
s.homepage = "https://github.com/daytonn/architecture-js"
|
118
120
|
s.licenses = ["MIT"]
|
119
121
|
s.require_paths = ["lib"]
|
120
|
-
s.rubygems_version = "1.8.
|
122
|
+
s.rubygems_version = "1.8.24"
|
121
123
|
s.summary = "architecture.js is a command line application to dynamically build and manage complex javascript applications."
|
122
124
|
|
123
125
|
if s.respond_to? :specification_version then
|
@@ -125,6 +127,7 @@ Gem::Specification.new do |s|
|
|
125
127
|
|
126
128
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
127
129
|
s.add_runtime_dependency(%q<listen>, [">= 0"])
|
130
|
+
s.add_runtime_dependency(%q<ejs>, [">= 0"])
|
128
131
|
s.add_runtime_dependency(%q<jsmin>, ["~> 1.0.1"])
|
129
132
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
130
133
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
@@ -133,6 +136,7 @@ Gem::Specification.new do |s|
|
|
133
136
|
s.add_runtime_dependency(%q<listen>, [">= 0"])
|
134
137
|
else
|
135
138
|
s.add_dependency(%q<listen>, [">= 0"])
|
139
|
+
s.add_dependency(%q<ejs>, [">= 0"])
|
136
140
|
s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
|
137
141
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
138
142
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -142,6 +146,7 @@ Gem::Specification.new do |s|
|
|
142
146
|
end
|
143
147
|
else
|
144
148
|
s.add_dependency(%q<listen>, [">= 0"])
|
149
|
+
s.add_dependency(%q<ejs>, [">= 0"])
|
145
150
|
s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
|
146
151
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
147
152
|
s.add_dependency(%q<bundler>, [">= 0"])
|
data/lib/architecture-js.rb
CHANGED
@@ -36,7 +36,8 @@ module ArchitectureJS
|
|
36
36
|
end
|
37
37
|
|
38
38
|
require "sprockets/lib/sprockets"
|
39
|
+
require "ejs"
|
39
40
|
|
40
|
-
%w(dependencies
|
41
|
+
%w(dependencies notification watcher blueprint architect).each do |lib|
|
41
42
|
require "architecture-js/#{lib}"
|
42
43
|
end
|
@@ -26,13 +26,8 @@ module Architect
|
|
26
26
|
|
27
27
|
def run
|
28
28
|
parse_command
|
29
|
-
|
30
|
-
|
31
|
-
parse_generate_options
|
32
|
-
else
|
33
|
-
parse_options
|
34
|
-
parse_arguments
|
35
|
-
end
|
29
|
+
parse_options
|
30
|
+
parse_arguments
|
36
31
|
|
37
32
|
if @command
|
38
33
|
self.send @command unless @command =~ /^-/
|
@@ -62,22 +57,8 @@ module Architect
|
|
62
57
|
puts ArchitectureJS::Notification.error e.message
|
63
58
|
end
|
64
59
|
|
65
|
-
def generate
|
66
|
-
@project = ArchitectureJS::Blueprint.new_from_config(@root)
|
67
|
-
config = {
|
68
|
-
arguments: @args,
|
69
|
-
template: @args.first,
|
70
|
-
filename: @args[1],
|
71
|
-
options: @template_options
|
72
|
-
}
|
73
|
-
@project.generator.generate config
|
74
|
-
rescue Exception => e
|
75
|
-
puts ArchitectureJS::Notification.error e.message
|
76
|
-
templates if @project
|
77
|
-
end
|
78
|
-
|
79
60
|
def compile
|
80
|
-
@project = ArchitectureJS::Blueprint.
|
61
|
+
@project = ArchitectureJS::Blueprint.init_with_config(@root)
|
81
62
|
compress = @options[:c] || @options[:compress]
|
82
63
|
@project.update(compress)
|
83
64
|
rescue Exception => e
|
@@ -85,7 +66,7 @@ module Architect
|
|
85
66
|
end
|
86
67
|
|
87
68
|
def watch
|
88
|
-
@project = ArchitectureJS::Blueprint.
|
69
|
+
@project = ArchitectureJS::Blueprint.init_with_config(@root)
|
89
70
|
@project.update
|
90
71
|
@watcher = @project.watch("architect is watching for changes. Type 'quit' to stop.")
|
91
72
|
start_interactive_session
|
@@ -93,16 +74,8 @@ module Architect
|
|
93
74
|
puts ArchitectureJS::Notification.error e.message
|
94
75
|
end
|
95
76
|
|
96
|
-
def templates
|
97
|
-
@project = ArchitectureJS::Blueprint.new_from_config(@root)
|
98
|
-
puts "Templates:"
|
99
|
-
@project.generator.templates.each { |k,v| puts " - #{k}" }
|
100
|
-
rescue Exception => e
|
101
|
-
puts ArchitectureJS::Notification.error e.message
|
102
|
-
end
|
103
|
-
|
104
77
|
def src_files
|
105
|
-
@project = ArchitectureJS::Blueprint.
|
78
|
+
@project = ArchitectureJS::Blueprint.init_with_config(@root)
|
106
79
|
puts "Source files:"
|
107
80
|
@project.src_files.each { |f| puts " - #{File.basename f}" }
|
108
81
|
rescue Exception => e
|
@@ -125,20 +98,13 @@ module Architect
|
|
125
98
|
when /help/
|
126
99
|
puts 'Interactive commands:'
|
127
100
|
puts ' compile - compile the application'
|
128
|
-
puts ' generate - generate a template'
|
129
|
-
puts ' templates - list available templates to generate'
|
130
101
|
puts ' src_files - list source files to be compiled into the build_dir'
|
131
102
|
puts ' help - show this menu'
|
132
103
|
puts ' quit - stop watching for changes'
|
133
|
-
when /compile|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
else
|
138
|
-
args = args.drop 1
|
139
|
-
parse_interactive_options args
|
140
|
-
parse_arguments args
|
141
|
-
end
|
104
|
+
when /compile|src_files/
|
105
|
+
args = args.drop 1
|
106
|
+
parse_interactive_options args
|
107
|
+
parse_arguments args
|
142
108
|
|
143
109
|
self.send @command
|
144
110
|
else
|
@@ -187,33 +153,6 @@ module Architect
|
|
187
153
|
end.parse!
|
188
154
|
end
|
189
155
|
|
190
|
-
def parse_generate_options
|
191
|
-
@options = {
|
192
|
-
help: false
|
193
|
-
}
|
194
|
-
@template_options = {}
|
195
|
-
|
196
|
-
@args.each_with_index do |arg, i|
|
197
|
-
# double dash options contain variables
|
198
|
-
if arg.match(/^--/)
|
199
|
-
option_key = arg.gsub(/^--/, '')
|
200
|
-
option_value = @args[i + 1]
|
201
|
-
|
202
|
-
if (option_value && option_value.match(/^-/) || option_value.nil?)
|
203
|
-
# no option value
|
204
|
-
@template_options[option_key.to_sym] = false
|
205
|
-
else
|
206
|
-
# option has a value
|
207
|
-
@template_options[option_key.to_sym] = option_value
|
208
|
-
end
|
209
|
-
# single dash options are flags
|
210
|
-
elsif arg.match(/^-/)
|
211
|
-
@template_options[arg.gsub(/^-/, '').to_sym] = true
|
212
|
-
end
|
213
|
-
end
|
214
|
-
# each_with_index
|
215
|
-
end
|
216
|
-
|
217
156
|
def parse_arguments(args = Array.try_convert(ARGV))
|
218
157
|
@args = args
|
219
158
|
@args.shift # remove command
|
@@ -7,11 +7,11 @@ module ArchitectureJS
|
|
7
7
|
:config_name,
|
8
8
|
:directories,
|
9
9
|
:template_directories,
|
10
|
-
:
|
10
|
+
:templates,
|
11
11
|
:config,
|
12
12
|
:raise_errors
|
13
13
|
|
14
|
-
def self.
|
14
|
+
def self.init_with_config(path)
|
15
15
|
config_file = Dir.entries(path).select {|f| f =~ /\.blueprint$/ }.first
|
16
16
|
|
17
17
|
raise ".blueprint file was not found in #{path}/" if config_file.nil?
|
@@ -29,23 +29,20 @@ module ArchitectureJS
|
|
29
29
|
@config_file = "#{config[:name].downcase}.blueprint"
|
30
30
|
root ||= Dir.getwd
|
31
31
|
@root = File.expand_path(root)
|
32
|
-
@template_directories = ["#{
|
32
|
+
@template_directories = ["#{@root}/templates"]
|
33
33
|
@directories = ['lib', 'src']
|
34
34
|
@config = {
|
35
35
|
blueprint: 'default',
|
36
36
|
src_dir: 'src',
|
37
37
|
build_dir: 'lib',
|
38
38
|
asset_root: '../',
|
39
|
-
output: 'compressed'
|
39
|
+
output: 'compressed',
|
40
|
+
template_dir: 'templates',
|
41
|
+
template_namespace: 'templates'
|
40
42
|
}
|
41
43
|
@config.merge! config unless config.nil?
|
44
|
+
@template_directories = [*@config[:template_dir]].map { |dir| "#{@root}/#{dir}" }
|
42
45
|
get_src_files
|
43
|
-
@generator = ArchitectureJS::Generator.new self
|
44
|
-
end
|
45
|
-
|
46
|
-
def add_templates(dir)
|
47
|
-
[*dir].each { |d| @template_directories << d }
|
48
|
-
@generator.load_templates
|
49
46
|
end
|
50
47
|
|
51
48
|
def read_config
|
@@ -94,6 +91,8 @@ module ArchitectureJS
|
|
94
91
|
def update(compress = false)
|
95
92
|
read_config
|
96
93
|
get_src_files
|
94
|
+
get_templates
|
95
|
+
create_templates_file unless @templates.empty?
|
97
96
|
compile_src_files
|
98
97
|
compress_application if compress || @config[:output] == 'compressed'
|
99
98
|
puts ArchitectureJS::Notification.log "application updated" unless @errors
|
@@ -107,6 +106,39 @@ module ArchitectureJS
|
|
107
106
|
end
|
108
107
|
end
|
109
108
|
|
109
|
+
def get_templates
|
110
|
+
@templates = {}
|
111
|
+
@template_directories.each do |dir|
|
112
|
+
find_templates_in_directory dir
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def find_templates_in_directory(dir)
|
117
|
+
dir_glob = File.join(dir, "**", "*.jst")
|
118
|
+
Dir.glob(dir_glob).each do |f|
|
119
|
+
name = get_template_name f, dir
|
120
|
+
@templates[name] = EJS.compile(File.read f)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_template_name(file, dir, ext = '.jst')
|
125
|
+
File.basename(file.gsub(/#{dir}\/?/, ''), ext)
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_templates_file
|
129
|
+
templates_string = ''
|
130
|
+
app_name = @config[:name]
|
131
|
+
template_namespace = @config[:template_namespace]
|
132
|
+
formatted_templates = @templates.map do |name, function|
|
133
|
+
"\"#{name}\": #{function}"
|
134
|
+
end
|
135
|
+
template = ERB.new File.read("#{ArchitectureJS::base_directory}/templates/templates_file.erb")
|
136
|
+
@compiled_templates_file = template.result binding
|
137
|
+
File.open("#{@root}/#{@config[:build_dir]}/templates.js", "w+") do |f|
|
138
|
+
f << @compiled_templates_file
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
110
142
|
def add_src_files_to_project(directory)
|
111
143
|
Dir["#{directory}/*.js"].each do |file|
|
112
144
|
src_filename = file.gsub(directory, '')
|
data/spec/architect_spec.rb
CHANGED
@@ -30,27 +30,13 @@ describe 'architect' do
|
|
30
30
|
File.exists?("#{TMP_DIR}/sub/src/myapp.js").should be_true
|
31
31
|
FileUtils.rm_rf "#{TMP_DIR}/sub"
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it 'should compile the application' do
|
35
35
|
`cd #{TMP_DIR}; #{@bin} compile`
|
36
36
|
File.exists?("#{TMP_DIR}/lib/myapp.js").should be_true
|
37
37
|
"#{TMP_DIR}/lib/myapp.js".should be_same_file_as "#{FIXTURES}/compressed.js"
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'should generate a template' do
|
41
|
-
`cd #{TMP_DIR}; #{@bin} generate blank src/test`
|
42
|
-
File.exists?("#{TMP_DIR}/src/test.js").should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should generate a template with options' do
|
46
|
-
FileUtils.mkdir("#{TMP_DIR}/templates")
|
47
|
-
FileUtils.cp("#{FIXTURES}/templates/test_template_two.js", "#{TMP_DIR}/templates/test_template.js")
|
48
|
-
`cd #{TMP_DIR}; #{@bin} generate test_template src/foo --optional_variable true --is_good -g --bool`
|
49
|
-
|
50
|
-
File.exists?("#{TMP_DIR}/src/foo.js").should be_true
|
51
|
-
"#{TMP_DIR}/src/foo.js".should be_same_file_as "#{FIXTURES}/test_template_options.js"
|
52
|
-
end
|
53
|
-
|
54
40
|
end
|
55
41
|
|
56
42
|
end
|
@@ -27,7 +27,7 @@ describe ArchitectureJS do
|
|
27
27
|
before :each do
|
28
28
|
FileUtils.mkdir("#{TMP_DIR}")
|
29
29
|
FileUtils.cp "#{FIXTURES}/existing.blueprint", "#{TMP_DIR}/myapp.blueprint"
|
30
|
-
suppress_output { @project = ArchitectureJS::Blueprint.
|
30
|
+
suppress_output { @project = ArchitectureJS::Blueprint.init_with_config(TMP_DIR) }
|
31
31
|
end
|
32
32
|
|
33
33
|
after :each do
|
@@ -36,7 +36,7 @@ describe ArchitectureJS do
|
|
36
36
|
|
37
37
|
it "should raise an error if there is no .blueprint file" do
|
38
38
|
FileUtils.rm_rf "#{TMP_DIR}/myapp.blueprint"
|
39
|
-
lambda { ArchitectureJS::Blueprint.
|
39
|
+
lambda { ArchitectureJS::Blueprint.init_with_config TMP_DIR }.should raise_error
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should set defaults from config file' do
|
@@ -46,7 +46,9 @@ describe ArchitectureJS do
|
|
46
46
|
build_dir: 'dest',
|
47
47
|
asset_root: '../',
|
48
48
|
output: 'compressed',
|
49
|
-
|
49
|
+
template_dir: 'templates',
|
50
|
+
template_namespace: 'templates',
|
51
|
+
name: 'test'
|
50
52
|
}
|
51
53
|
end
|
52
54
|
|
data/spec/blueprint_spec.rb
CHANGED
@@ -39,11 +39,7 @@ describe ArchitectureJS::Blueprint do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should have template_directories" do
|
42
|
-
@project.template_directories.should == ["#{
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should have a generator" do
|
46
|
-
@project.generator.should_not be_nil
|
42
|
+
@project.template_directories.should == ["#{TMP_DIR}/templates"]
|
47
43
|
end
|
48
44
|
|
49
45
|
context "with existing project" do
|
@@ -52,7 +48,7 @@ describe ArchitectureJS::Blueprint do
|
|
52
48
|
end
|
53
49
|
|
54
50
|
it "should initialize with a config path" do
|
55
|
-
@existing = ArchitectureJS::Blueprint.
|
51
|
+
@existing = ArchitectureJS::Blueprint.init_with_config TMP_DIR
|
56
52
|
@existing.config.should_not be_empty
|
57
53
|
@existing.config[:name].should == 'myapp'
|
58
54
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Hello my name is <%= person.name %>, I am <%= person.age %></p>
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
describe 'Templates' do
|
4
|
+
|
5
|
+
describe 'without template files' do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
FileUtils.mkdir TMP_DIR
|
9
|
+
suppress_output do
|
10
|
+
@project = ArchitectureJS::Blueprint.new({ name: 'myapp' }, TMP_DIR)
|
11
|
+
@project.create
|
12
|
+
end
|
13
|
+
suppress_output { @project.update }
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
FileUtils.rm_rf "#{TMP_DIR}" if File.exists? "#{TMP_DIR}"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not create a templates.js file in the build_dir' do
|
21
|
+
File.exists?("#{TMP_DIR}/lib/templates.js").should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with one template_dir and one template file" do
|
27
|
+
before :each do
|
28
|
+
FileUtils.mkdir TMP_DIR
|
29
|
+
suppress_output do
|
30
|
+
@project = ArchitectureJS::Blueprint.new({ name: 'myapp' }, TMP_DIR)
|
31
|
+
@project.create
|
32
|
+
end
|
33
|
+
FileUtils.mkdir "#{TMP_DIR}/templates"
|
34
|
+
FileUtils.cp "#{FIXTURES}/test_template.jst", "#{TMP_DIR}/templates/test_template.jst"
|
35
|
+
suppress_output { @project.update }
|
36
|
+
end
|
37
|
+
|
38
|
+
after :each do
|
39
|
+
FileUtils.rm_rf "#{TMP_DIR}" if File.exists? "#{TMP_DIR}"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have one template' do
|
43
|
+
@project.templates['test_template'].should_not be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should create a templates file in the build directory' do
|
47
|
+
File.exists?("#{TMP_DIR}/lib/templates.js").should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'with multiple template_dirs and multiple templates' do
|
53
|
+
before :each do
|
54
|
+
FileUtils.mkdir TMP_DIR
|
55
|
+
suppress_output do
|
56
|
+
project = ArchitectureJS::Blueprint.new({ name: 'myapp' }, TMP_DIR)
|
57
|
+
project.create
|
58
|
+
FileUtils.cp "#{FIXTURES}/multiple_templates.blueprint", "#{TMP_DIR}/myapp.blueprint"
|
59
|
+
FileUtils.mkdir "#{TMP_DIR}/templates"
|
60
|
+
FileUtils.mkdir "#{TMP_DIR}/more_templates"
|
61
|
+
FileUtils.cp "#{FIXTURES}/test_template.jst", "#{TMP_DIR}/templates/test_template.jst"
|
62
|
+
FileUtils.cp "#{FIXTURES}/test_template.jst", "#{TMP_DIR}/more_templates/another_template.jst"
|
63
|
+
@project = ArchitectureJS::Blueprint.init_with_config(TMP_DIR)
|
64
|
+
end
|
65
|
+
suppress_output { @project.update }
|
66
|
+
end
|
67
|
+
|
68
|
+
after :each do
|
69
|
+
FileUtils.rm_rf "#{TMP_DIR}" if File.exists? "#{TMP_DIR}"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should use alternate namespace' do
|
73
|
+
File.read("#{TMP_DIR}/lib/templates.js").match(/^myapp\.Foo/).should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should have multiple template directories' do
|
77
|
+
puts @project.template_directories
|
78
|
+
@project.template_directories.length.should == 2
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should have two templates' do
|
82
|
+
@project.templates['test_template'].should_not be_nil
|
83
|
+
@project.templates['another_template'].should_not be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should create a templates file in the build directory' do
|
87
|
+
File.exists?("#{TMP_DIR}/lib/templates.js").should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: architecture-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: listen
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ejs
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: jsmin
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +156,7 @@ files:
|
|
140
156
|
- AUTHORS
|
141
157
|
- Gemfile
|
142
158
|
- Gemfile.lock
|
159
|
+
- Guardfile
|
143
160
|
- HELP
|
144
161
|
- LICENSE.txt
|
145
162
|
- README.md
|
@@ -153,7 +170,6 @@ files:
|
|
153
170
|
- lib/architecture-js/architect.rb
|
154
171
|
- lib/architecture-js/blueprint.rb
|
155
172
|
- lib/architecture-js/dependencies.rb
|
156
|
-
- lib/architecture-js/generator.rb
|
157
173
|
- lib/architecture-js/helpers.rb
|
158
174
|
- lib/architecture-js/notification.rb
|
159
175
|
- lib/architecture-js/watcher.rb
|
@@ -212,22 +228,24 @@ files:
|
|
212
228
|
- spec/fixtures/lib1_compressed.js
|
213
229
|
- spec/fixtures/lib2.js
|
214
230
|
- spec/fixtures/lib2_compressed.js
|
231
|
+
- spec/fixtures/multiple_templates.blueprint
|
215
232
|
- spec/fixtures/myapp.blueprint
|
216
233
|
- spec/fixtures/src_file.js
|
217
234
|
- spec/fixtures/templates/env_template.js
|
218
235
|
- spec/fixtures/templates/test_template_one.js
|
219
236
|
- spec/fixtures/templates/test_template_two.js
|
220
237
|
- spec/fixtures/test_blueprint.rb
|
238
|
+
- spec/fixtures/test_template.jst
|
221
239
|
- spec/fixtures/test_template_options.js
|
222
240
|
- spec/fixtures/test_template_two.js
|
223
241
|
- spec/fixtures/underscore_template.js
|
224
242
|
- spec/fixtures/update.blueprint
|
225
243
|
- spec/fixtures/update.js
|
226
|
-
- spec/generator_spec.rb
|
227
244
|
- spec/helpers_spec.rb
|
228
245
|
- spec/notification_spec.rb
|
229
246
|
- spec/spec_helper.rb
|
230
|
-
-
|
247
|
+
- spec/templates_spec.rb
|
248
|
+
- templates/templates_file.erb
|
231
249
|
homepage: https://github.com/daytonn/architecture-js
|
232
250
|
licenses:
|
233
251
|
- MIT
|
@@ -243,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
261
|
version: '0'
|
244
262
|
segments:
|
245
263
|
- 0
|
246
|
-
hash:
|
264
|
+
hash: 278530094311869968
|
247
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
266
|
none: false
|
249
267
|
requirements:
|
@@ -252,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
270
|
version: '0'
|
253
271
|
requirements: []
|
254
272
|
rubyforge_project:
|
255
|
-
rubygems_version: 1.8.
|
273
|
+
rubygems_version: 1.8.24
|
256
274
|
signing_key:
|
257
275
|
specification_version: 3
|
258
276
|
summary: architecture.js is a command line application to dynamically build and manage
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module ArchitectureJS
|
2
|
-
class Generator
|
3
|
-
|
4
|
-
attr_accessor :template_paths,
|
5
|
-
:templates,
|
6
|
-
:blueprint,
|
7
|
-
:project
|
8
|
-
|
9
|
-
def initialize(blueprint)
|
10
|
-
@project = blueprint
|
11
|
-
@blueprint = @project.config
|
12
|
-
@template_paths = @project.template_directories
|
13
|
-
@templates = Hash.new
|
14
|
-
load_templates
|
15
|
-
end
|
16
|
-
|
17
|
-
def find_templates(paths)
|
18
|
-
[*paths].each do |path|
|
19
|
-
Dir["#{path}/*"].each do |file|
|
20
|
-
add_file_to_templates file
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def load_templates
|
26
|
-
find_templates @template_paths
|
27
|
-
end
|
28
|
-
|
29
|
-
def add_file_to_templates(file)
|
30
|
-
ext = File.extname(file)
|
31
|
-
template_name = File.basename(file, ext)
|
32
|
-
@templates[template_name] = {
|
33
|
-
erb: read_template(file),
|
34
|
-
ext: ext
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def read_template(file)
|
39
|
-
ERB.new(File.read(file), nil, '<>')
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate(config)
|
43
|
-
raise "You must provide a template to generate:\n - architect generate <template>" unless config[:template]
|
44
|
-
raise "There is no template named '#{template}' in the #{@blueprint[:name]} project" unless @templates[config[:template]]
|
45
|
-
|
46
|
-
template = config[:template]
|
47
|
-
options = config[:options]
|
48
|
-
arguments = config[:arguments]
|
49
|
-
filename = "#{config[:filename]}#{@templates[template][:ext]}"
|
50
|
-
|
51
|
-
generate_file(filename, render_template(template, filename, arguments, options))
|
52
|
-
end
|
53
|
-
|
54
|
-
def generate_file(filename, template, path = nil)
|
55
|
-
path ||= File.expand_path(Dir.getwd)
|
56
|
-
File.open("#{path}/#{filename}", "w+") { |f| f.write template }
|
57
|
-
puts ArchitectureJS::Notification.added "#{filename} generated" if File.exists?("#{path}/#{filename}")
|
58
|
-
end
|
59
|
-
|
60
|
-
def render_template(template, filename, arguments, options)
|
61
|
-
blueprint = @blueprint
|
62
|
-
project = @project
|
63
|
-
@templates[template][:erb].result(binding)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/spec/generator_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ArchitectureJS::Generator do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
FileUtils.mkdir TMP_DIR
|
7
|
-
FileUtils.mkdir "#{TMP_DIR}/templates"
|
8
|
-
FileUtils.cp "#{FIXTURES}/templates/test_template_one.js", "#{TMP_DIR}/test_template_one.js"
|
9
|
-
FileUtils.cp "#{FIXTURES}/templates/test_template_two.js", "#{TMP_DIR}/test_template_two.js"
|
10
|
-
FileUtils.cp "#{FIXTURES}/templates/env_template.js", "#{TMP_DIR}/env_template.js"
|
11
|
-
|
12
|
-
project = ArchitectureJS::Blueprint.new({ name: 'myapp' }, TMP_DIR)
|
13
|
-
project.add_templates "#{FIXTURES}/templates"
|
14
|
-
@gen = project.generator
|
15
|
-
end
|
16
|
-
|
17
|
-
after :each do
|
18
|
-
FileUtils.rm_rf TMP_DIR if File.exists? TMP_DIR
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should have a project' do
|
22
|
-
@gen.project.class.should == ArchitectureJS::Blueprint
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have a blueprint' do
|
26
|
-
@gen.blueprint.class.should_not be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should have template_paths' do
|
30
|
-
@gen.template_paths.should == ["#{ArchitectureJS::base_directory}/templates", "#{TMP_DIR}/templates", "#{FIXTURES}/templates"]
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should find all the templates' do
|
34
|
-
@gen.templates['test_template_one'].should_not be_nil
|
35
|
-
@gen.templates['test_template_two'].should_not be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should render a template' do
|
39
|
-
@gen.render_template('test_template_one', 'test', [], {}).should == File.open("#{FIXTURES}/templates/test_template_one.js").read
|
40
|
-
@gen.render_template('test_template_two', 'test', [], {}).should == File.open("#{FIXTURES}/test_template_two.js").read
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should render a template with options' do
|
44
|
-
@gen.render_template('test_template_two', 'test', [], { optional_variable: 'true' }).should == File.open("#{FIXTURES}/test_template_options.js").read
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should generate a file from a template' do
|
48
|
-
suppress_output { @gen.generate_file("test.js", @gen.render_template("test_template_two", "test", [], {}), TMP_DIR) }
|
49
|
-
File.exists?("#{TMP_DIR}/test.js").should be_true
|
50
|
-
File.open("#{TMP_DIR}/test.js").read.should == File.open("#{FIXTURES}/test_template_two.js").read
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should pass the arguments to the template' do
|
54
|
-
suppress_output { @gen.generate_file("env-test.js", @gen.render_template("env_template", "env-test", ['module', 'foo', '-f', '--name', 'Something'], {}), TMP_DIR) }
|
55
|
-
File.open("#{TMP_DIR}/env-test.js").read.should == File.open("#{FIXTURES}/env-test.js").read
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
data/templates/blank.js
DELETED
File without changes
|