architecture-js 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ rvm: 1.9.2
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # architecture-js
1
+ # architecture-js [![Build Status](https://secure.travis-ci.org/daytonn/architecture-js.png)](http://travis-ci.org/daytonn/architecture-js)
2
2
 
3
3
  ##About
4
4
 
5
- Architecture.js is a suite of tools to help you build and manage complex javascript applications and frameworks. With architecture.js you can create project scaffolding, manage third-party packages, compile, and compress your javascript application, all in real time as you write plain old vanilla javascript. In addition to large applications, architecture.js is perfect for developing your own javascript frameworks.
5
+ ArchitectureJS is a suite of tools to help you build and manage complex javascript applications and frameworks. With ArchitectureJS you can create project scaffolding, manage third-party packages, compile, and compress your javascript application, all in real time as you write plain old vanilla javascript. In addition to large applications, ArchitectureJS is perfect for developing your own javascript frameworks and libraries.
6
6
 
7
7
  ###contributing to architecture.js
8
8
 
@@ -14,7 +14,7 @@ Architecture.js is a suite of tools to help you build and manage complex javascr
14
14
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
15
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
16
 
17
- == Copyright
17
+ ##Copyright
18
18
 
19
19
  Copyright (c) 2011 Dayton Nolan. See LICENSE.txt for
20
20
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "architecture-js"
8
- s.version = "0.1.3"
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 = ["Dayton Nolan"]
12
- s.date = "2011-12-28"
12
+ s.date = "2012-01-28"
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"]
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".DS_Store",
22
22
  ".document",
23
+ ".travis.yml",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE.txt",
@@ -29,6 +30,7 @@ Gem::Specification.new do |s|
29
30
  "architecture-js.gemspec",
30
31
  "bin/architect",
31
32
  "lib/architecture-js.rb",
33
+ "lib/architecture-js/architect.rb",
32
34
  "lib/architecture-js/command.rb",
33
35
  "lib/architecture-js/dependencies.rb",
34
36
  "lib/architecture-js/generator.rb",
@@ -39,21 +41,26 @@ Gem::Specification.new do |s|
39
41
  "spec/architecture-js_spec.rb",
40
42
  "spec/cli_spec.rb",
41
43
  "spec/command_spec.rb",
44
+ "spec/fixtures/.DS_Store",
42
45
  "spec/fixtures/compiled_src.js",
43
- "spec/fixtures/ejs_template.ejs",
46
+ "spec/fixtures/compressed.architecture",
47
+ "spec/fixtures/compressed.js",
48
+ "spec/fixtures/ejs.ejs",
44
49
  "spec/fixtures/existing.architecture",
45
50
  "spec/fixtures/lib1.js",
46
51
  "spec/fixtures/lib2.js",
47
52
  "spec/fixtures/myapp.architecture",
48
53
  "spec/fixtures/src_file.js",
49
- "spec/fixtures/test_template.erb",
50
- "spec/fixtures/test_template.js",
54
+ "spec/fixtures/templates/test_template_one.js",
55
+ "spec/fixtures/templates/test_template_two.js",
51
56
  "spec/fixtures/test_template_options.js",
57
+ "spec/fixtures/test_template_two.js",
52
58
  "spec/generator_spec.rb",
53
59
  "spec/helpers_spec.rb",
54
60
  "spec/notification_spec.rb",
55
61
  "spec/project_spec.rb",
56
- "spec/spec_helper.rb"
62
+ "spec/spec_helper.rb",
63
+ "templates/blank.js"
57
64
  ]
58
65
  s.homepage = "http://github.com/daytonn/architecture.js"
59
66
  s.licenses = ["MIT"]
data/bin/architect CHANGED
@@ -1,214 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
4
-
5
- begin
6
- require 'architecture-js'
7
- require 'optparse'
8
- rescue LoadError
9
- require 'rubygems'
10
- require 'architecture-js'
11
- require 'optparse'
12
- end
13
-
14
- create = <<-CREATE
15
- create Creates a new architecture-js application in the current working
16
- directory or sub directory within.
17
-
18
- Arguments:
19
- application name - Name of the architecture-js application
20
- subdirectory* - Directory where the application will be
21
- installed (created if non existent)
22
-
23
- examples:
24
- architect create myapp
25
- architect create myapp subdirectory
26
- CREATE
27
-
28
- generate = <<-GEN
29
- generate Generates scoffolding for the given component file type.
30
-
31
- Arguments:
32
- type - Type of application scaffold to create (module, elements, model).
33
- name* - Name of the module to generate the scaffold for
34
-
35
- Options:
36
- -a, --alias name* - Create an alias of the application object
37
- (defaults to "app"), passing a name is optional
38
- -e, --elements - Generate an elements file
39
- -m, --model - Generate a model file
40
-
41
- examples:
42
- architect generate module mymodule -em (generates module, elements and model)
43
- architect generate module mymodule -a (generates an application alias)
44
- architect generate elements mymodule -m (generates an elements and a model file)
45
- architect generate model mymodule (generates an model file)
46
- GEN
47
-
48
- compile = <<-COMP
49
- compile Compiles the architecture-js project in the current working directory.
50
-
51
- Options:
52
- -c, --compress - Compress output with JsMin
53
-
54
- example:
55
- architect compile
56
- COMP
57
-
58
- watch = <<-WATCH
59
- watch Watches the current working directory for file changes and
60
- compiles when changes are detected.
61
-
62
- example:
63
- architect watch
64
- WATCH
65
-
66
- upd = <<-UPDATE
67
- update Updates your application's core files to the latest version.
68
- UPDATE
69
-
70
- footer = <<-FOOTER
71
- * optional argument
72
- FOOTER
73
-
74
- help = {
75
- create: create,
76
- generate: generate,
77
- compile: compile,
78
- watch: watch,
79
- update: upd,
80
- footer: footer
81
- }
82
-
83
- command = ARGV[0]
84
-
85
- options = {
86
- alias: nil,
87
- elements: false,
88
- model: false,
89
- help: false,
90
- compress: nil
91
- }
92
-
93
- optparse = OptionParser.new do |opts|
94
- opts.on( '-h', '--help', 'Display this screen' ) do
95
- options[:help] = true
96
- end
97
-
98
- opts.on( '-v', '--version', 'Display the version') do
99
- time = Time.now
100
- puts ArchitectureJS::Notification.notice 'architect ' + ArchitectureJS::VERSION
101
- puts ArchitectureJS::Notification.notice "Copyright (c) #{time.year} Dayton Nolan"
102
- puts ArchitectureJS::Notification.notice "Released under the MIT License"
103
- exit
104
- end
105
-
106
- opts.on( '-a', '--alias [alias]', 'Generate application alias') do |als|
107
- options[:alias] = als || "app"
108
- end
109
-
110
- opts.on( '-d', '--dest [dest]', 'Module destination directory') do |dest|
111
- options[:dest] = dest
112
- end
113
-
114
- opts.on('-e', '--elements', 'Generate elements file') do
115
- options[:elements] = true
116
- end
117
-
118
- opts.on('-m', '--model', 'Generate model file') do
119
- options[:model] = true
120
- end
121
-
122
- opts.on('-c', '--compress', 'Compress with JsMin') do
123
- options[:compress] = true
124
- end
125
- end
126
-
127
- optparse.parse!
128
-
129
- case command
130
- # create
131
- when "create"
132
- if options[:help]
133
- puts help[:create]
134
- exit
135
- end
136
- app_name = ARGV[1]
137
- sub_dir = ARGV[2] || nil
138
-
139
- if app_name.nil?
140
- puts "Error! Application name is required (architect create app_name)"
141
- exit
142
- end
143
-
144
- config = { name: app_name }
145
- config[:root] = sub_dir unless sub_dir.nil?
146
- ArchitectureJS::Command.create(config)
147
- # generate
148
- when "generate"
149
- if options[:help]
150
- puts help[:generate]
151
- exit
152
- end
153
-
154
- errors = Hash.new
155
- type = ARGV[1]
156
- name = ARGV[2]
157
- als = options[:alias] || nil
158
- dest = options[:dest] || nil
159
-
160
- errors[:type] = "Error! Scaffold type is required (architect generate module mymodule)" if type.nil?
161
- errors[:name] = "Error! Module name is required (architect generate module mymodule)" if name.nil?
162
-
163
- unless errors.empty?
164
- errors.each do |error|
165
- puts error
166
- end
167
- exit
168
- end
169
-
170
- dependencies = {
171
- model: options[:model],
172
- elements: options[:elements]
173
- }
174
-
175
- ArchitectureJS::Command.generate({
176
- project: ArchitectureJS::Project.new,
177
- type: type,
178
- name: name,
179
- alias: als,
180
- dest: dest,
181
- dependencies: dependencies
182
- })
183
- # compile
184
- when "compile"
185
- if options[:help]
186
- puts help[:compile]
187
- exit
188
- end
189
-
190
- if options[:compress]
191
- ArchitectureJS::Command.compile
192
- else
193
- ArchitectureJS::Command.compile({ force_compress: options[:compress] })
194
- end
195
- # watch
196
- when "watch"
197
- if options[:help]
198
- puts help[:watch]
199
- exit
200
- end
201
- ArchitectureJS::Command.watch
202
- # update
203
- when "update"
204
- if options[:help]
205
- puts help[:update]
206
- exit
207
- end
208
- ArchitectureJS::Command.update
209
- else
210
- help.each do |section|
211
- puts section.last + "\n"
212
- end
213
- exit
214
- end
3
+ require 'architecture-js'
4
+ Architect::application.run
@@ -0,0 +1,174 @@
1
+ module Architect
2
+
3
+ class << self
4
+
5
+ def application
6
+ @application ||= Architect::Application.new
7
+ end
8
+
9
+ end
10
+
11
+ class Application
12
+
13
+ attr_reader :args,
14
+ :command,
15
+ :commands,
16
+ :options,
17
+ :subcommands
18
+
19
+ def initialize
20
+ @command = ARGV[0].to_sym if ARGV[0]
21
+ @args = Array.try_convert(ARGV)
22
+ @args.shift
23
+ @options = {}
24
+ @subcommands = {}
25
+ @commands = [:create, :generate, :compile, :watch]
26
+ @help = create_help
27
+ end
28
+
29
+ def run
30
+ parse_args unless @args.empty?
31
+ if @command
32
+ if options[:h]
33
+ help @command
34
+ else
35
+ if @commands.include? @command
36
+ self.send @command
37
+ else
38
+ puts ArchitectureJS::Notification.error "#{@command} is not a valid command"
39
+ end
40
+ end
41
+ else
42
+ help
43
+ end
44
+ end
45
+
46
+ def create
47
+ app_name = @args[0]
48
+ sub_dir = @args[1] || nil
49
+
50
+ if app_name.nil?
51
+ puts "Error! Application name is required (architect create app_name)"
52
+ exit
53
+ end
54
+
55
+ config = { name: app_name }
56
+ config[:root] = sub_dir unless sub_dir.nil?
57
+ ArchitectureJS::Command.create(config)
58
+ end
59
+
60
+ def generate
61
+ puts 'To be implemented'
62
+ end
63
+
64
+ def compile
65
+ if options[:c] || options[:compress]
66
+ ArchitectureJS::Command.compile
67
+ else
68
+ ArchitectureJS::Command.compile({ force_compress: true })
69
+ end
70
+ end
71
+
72
+ def watch
73
+ ArchitectureJS::Command.watch
74
+ end
75
+
76
+ private
77
+ def parse_args
78
+ @args.each_index do |i|
79
+ if @args[i] =~ /^\-/
80
+ parse_flag @args[i]
81
+ elsif args[i] =~ /\:/
82
+ parse_key_value_pair @args[i]
83
+ else
84
+ add_subcommand @args[i], i
85
+ end
86
+ end
87
+ end
88
+
89
+ def parse_flag(arg)
90
+ key = arg.gsub(/^\-+/, '')
91
+ @options[key] = true
92
+ @options[key.to_sym] = true
93
+ end
94
+
95
+ def parse_key_value_pair(arg)
96
+ m = arg.match(/([\w|\-|]+)\:(\"|\')?(.*)(\"|\')?/)
97
+ key = m.captures[0]
98
+ value = m.captures[2]
99
+ @options[key] = value
100
+ @options[key.to_sym] = value
101
+ end
102
+
103
+ def add_subcommand(arg, index)
104
+ #@subcommands[arg] = [sub args]
105
+ end
106
+
107
+ def help(command = nil)
108
+ help = command || [*@commands, :footer]
109
+ [*help].each do |command|
110
+ puts @help[command]
111
+ end
112
+ end
113
+
114
+ def create_help
115
+ help = {}
116
+ help[:create] = <<-CREATE
117
+ create Creates a new architecture-js application in the current working
118
+ directory or sub directory within.
119
+
120
+ Arguments:
121
+ application name - Name of the architecture-js application
122
+ subdirectory* - Directory where the application will be
123
+ installed (created if nonexistent)
124
+
125
+ examples:
126
+ architect create myapp
127
+ architect create myapp subdirectory
128
+ CREATE
129
+
130
+ help[:generate] = <<-GEN
131
+ generate Generates scoffolding from a template.
132
+
133
+ Arguments:
134
+ name - Name of the template to generate
135
+
136
+ Options:
137
+ *Options are arbitrary (optional) arguments specific to templates
138
+ There are two types of options: boolean and named attributes
139
+
140
+ examples:
141
+ architect generate mytemplate -f (boolean arguments use a single "-")
142
+ architect generate mytemplate foo:"Hello" (named arguments can be boolean by passing no value)
143
+ architect genreate mymodule -f foo:"Hello" (combined to generate complex templates)
144
+ GEN
145
+
146
+ help[:compile] = <<-COMP
147
+ compile Compiles the architecture-js project in the current working directory.
148
+
149
+ Options:
150
+ -c, --compress - Compress output with JsMin
151
+
152
+ example:
153
+ architect compile
154
+ COMP
155
+
156
+ help[:watch] = <<-WATCH
157
+ watch Watches the current working directory for file changes and
158
+ compiles when changes are detected.
159
+
160
+ example:
161
+ architect watch
162
+ WATCH
163
+
164
+ help[:footer] = <<-FOOTER
165
+
166
+ * optional argument
167
+
168
+ FOOTER
169
+
170
+ help
171
+ end
172
+ end
173
+
174
+ end
@@ -6,11 +6,10 @@ module ArchitectureJS
6
6
  path ||= File.expand_path(Dir.getwd)
7
7
 
8
8
  puts ArchitectureJS::Notification.log "ArchitectureJS are watching for changes. Press Ctrl-C to stop."
9
- project = ArchitectureJS::Project.new({ name: 'unknown' }, path)
10
- project.read_config
9
+ project = ArchitectureJS::Project::new_from_config(path)
11
10
  project.update
12
11
  watch_hash = Hash.new
13
-
12
+ puts project.watch_directories
14
13
  project.watch_directories.each do |dir|
15
14
  watch_hash["#{path}/#{dir}"] = "**/*.js"
16
15
  end
@@ -1,44 +1,51 @@
1
1
  module ArchitectureJS
2
2
  class Generator
3
3
 
4
- attr_reader :template_paths,
5
- :templates,
6
- :project
4
+ attr_accessor :template_paths,
5
+ :templates,
6
+ :project
7
7
 
8
8
  def initialize(project)
9
9
  @project = project
10
10
  @template_paths = @project.template_directories
11
11
  @templates = Hash.new
12
12
  find_templates @template_paths
13
- #@template_dir = template_dir
14
- #@template_files = Dir.entries(template_dir).reject {|file| file.match /^\./ }
15
- #@templates = Hash.new
16
- #@template_files.each do |file|
17
- # name = file.gsub /\.\w+$/, ''
18
- # @templates[name] = ERB.new(File.read(File.expand_path(file, @template_dir)))
19
- #end
20
13
  end
21
14
 
22
15
  def find_templates(paths)
23
16
  paths.each do |path|
24
- Dir["#{path}/*_template*"].each do |file|
25
- template_name = get_template_name file
26
- @templates[template_name] = get_template(file)
17
+ Dir["#{path}/*"].each do |file|
18
+ add_file_to_templates file
27
19
  end
28
20
  end
29
21
  end
30
22
 
31
- def get_template_name(file)
32
- file.split(/\/|\\/).last.gsub(/_template\.\w*/, '')
23
+ def add_file_to_templates(file)
24
+ ext = File.extname(file)
25
+ template_name = File.basename(file, ext)
26
+ @templates[template_name] = {
27
+ erb: read_template(file),
28
+ ext: ext
29
+ }
33
30
  end
34
31
 
35
- def get_template(file)
32
+ def read_template(file)
36
33
  ERB.new File.read(file)
37
34
  end
38
35
 
36
+ def generate(template, filename, options)
37
+ filename = "#{filename}#{@templates[template][:ext]}"
38
+ generate_file(filename, render_template(template, options), path)
39
+ end
40
+
41
+ def generate_file(filename, template, path = nil)
42
+ path ||= File.expand_path(Dir.getwd)
43
+ File.open("#{path}/#{filename}", "w+") { |f| f.write template }
44
+ end
45
+
39
46
  def render_template(template, options = nil)
40
47
  project = @project
41
- @templates[template].result(binding)
48
+ @templates[template][:erb].result(binding)
42
49
  end
43
50
  end
44
51
  end
@@ -1,19 +1,31 @@
1
1
  module ArchitectureJS
2
- class Project # TODO make generator belong to project to have default templates hooked up to generator
3
- attr_reader :root,
4
- :src_files,
5
- :framework,
6
- :config_name,
7
- :watch_directories,
8
- :directories,
9
- :template_directories,
10
- :generator
11
-
12
- attr_accessor :config
2
+ class Project
3
+ attr_accessor :root,
4
+ :src_files,
5
+ :framework,
6
+ :config_name,
7
+ :watch_directories,
8
+ :directories,
9
+ :template_directories,
10
+ :generator,
11
+ :config
13
12
 
14
13
  # this line adds the default framework to ArchitectureJS
15
14
  ArchitectureJS::register_framework 'none', self
16
15
 
16
+ def self.new_from_config(path)
17
+ config_file = Dir.entries(path).select {|f| f =~ /\.architecture$/ }.first
18
+
19
+ raise ".architecture file was not found in #{path}" if config_file.nil?
20
+
21
+ config = YAML::load_file "#{path}/#{config_file}"
22
+ config = ArchitectureJS::Helpers::symbolize_keys config
23
+
24
+ raise "#{config[:framework]} is unavailable or not installed" if ArchitectureJS::FRAMEWORKS[config[:framework]].nil?
25
+
26
+ project = ArchitectureJS::FRAMEWORKS[config[:framework]].new config, path
27
+ end
28
+
17
29
  def initialize(config, root = nil)
18
30
  raise "#{self.class}.new({ name: 'myapp' }, options): config[:name] is undefined" unless config[:name]
19
31
  @config_file = "#{config[:name].downcase}.architecture"
@@ -35,7 +47,7 @@ module ArchitectureJS
35
47
  end
36
48
 
37
49
  def read_config
38
- config = YAML.load_file("#{@root}/#{@config_file}")
50
+ config = YAML::load_file("#{@root}/#{@config_file}")
39
51
  assign_config_variables config
40
52
  end
41
53
 
@@ -79,7 +91,7 @@ module ArchitectureJS
79
91
  def update
80
92
  get_src_files
81
93
  compile_src_files
82
- compress_application if @output == 'compressed'
94
+ compress_application if @config[:output] == 'compressed'
83
95
  puts ArchitectureJS::Notification.log "application updated" unless @errors
84
96
  @errors = false
85
97
  end
@@ -123,15 +135,14 @@ module ArchitectureJS
123
135
  end
124
136
 
125
137
  def compress_application
126
- app_root = File.expand_path "#{@config[:build_dir]}"
127
- src_files = Dir.entries(app_root)
128
- src_files.reject! { |file| file =~ /^\./ }
138
+ app_root = File.expand_path "#{@root}/#{@config[:build_dir]}"
139
+ src_files = Dir.entries(app_root).reject! { |file| file =~ /^\./ }
129
140
 
130
- src_files.each do |module_file|
131
- full_path = "#{app_root}/#{module_file}"
141
+ src_files.each do |file|
142
+ full_path = "#{app_root}/#{file}"
132
143
  uncompressed = File.open(full_path, "r").read
133
- File.open(full_path, "w+") do |module_file|
134
- module_file << JSMin.minify(uncompressed)
144
+ File.open(full_path, "w+") do |file|
145
+ file << JSMin.minify(uncompressed).gsub(/\n?/, '')
135
146
  end
136
147
  end
137
148
  end
data/spec/cli_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
-
2
+ # TODO write tests for CLI
3
3
  describe 'CLI' do
4
4
  before :each do
5
5
  @bin = "#{ArchitectureJS::BASE_DIR}/bin/architect"
@@ -35,4 +35,8 @@ describe 'CLI' do
35
35
  "#{TMP_DIR}/lib/myapp.js".should be_same_file_as "#{FIXTURES}/compiled_src.js"
36
36
  end
37
37
 
38
+ it 'should generate a template' do
39
+ #suppress_output { %x`cd #{TMP_DIR}; #{@bin} generate blank test` }
40
+ #File.exists?("#{TMP_DIR}/test.js").should be_true
41
+ end
38
42
  end
Binary file
@@ -0,0 +1,6 @@
1
+ framework: none
2
+ src_dir: src
3
+ build_dir: lib
4
+ asset_root: ../
5
+ output: compressed
6
+ name: myapp
@@ -0,0 +1 @@
1
+ var file_one='one';var file_two='two';
File without changes
@@ -0,0 +1,6 @@
1
+ var myapp = (function() {
2
+ function myapp() {
3
+
4
+ }
5
+ return myapp;
6
+ })();
@@ -1,49 +1,46 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe ArchitectureJS::Generator do
4
4
 
5
5
  before :each do
6
6
  FileUtils.mkdir TMP_DIR
7
7
  FileUtils.mkdir "#{TMP_DIR}/templates"
8
- FileUtils.cp "#{FIXTURES}/test_template.erb", "#{TMP_DIR}/templates/test_template.erb"
9
- FileUtils.cp "#{FIXTURES}/ejs_template.ejs", "#{TMP_DIR}/templates/ejs_template.ejs"
10
- @gen = ArchitectureJS::Generator.new(ArchitectureJS::Project.new({ name: 'myapp' }, TMP_DIR))
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
+ project = ArchitectureJS::Project.new({ name: 'myapp' }, TMP_DIR)
11
+ project.template_directories = ["#{FIXTURES}/templates"]
12
+ @gen = ArchitectureJS::Generator.new(project)
11
13
  end
12
-
14
+
13
15
  after :each do
14
16
  FileUtils.rm_rf TMP_DIR if File.exists? TMP_DIR
15
17
  end
16
18
 
17
- it "should have a project" do
19
+ it 'should have a project' do
18
20
  @gen.project.class.should == ArchitectureJS::Project
19
21
  end
20
22
 
21
- it "should have template_paths" do
22
- @gen.template_paths.should == ["#{ArchitectureJS::BASE_DIR}/templates", "#{TMP_DIR}/templates"]
23
- end
24
-
25
- it "should get a template name" do
26
- @gen.get_template_name("/Volumes/Storage/Development/architecture-js/spec/tmp/templates/ejs_template.ejs").should == 'ejs'
27
- @gen.get_template_name("/Volumes/Storage/Development/architecture-js/spec/tmp/templates/test_template.erb").should == 'test'
23
+ it 'should have template_paths' do
24
+ @gen.template_paths.should == ["#{FIXTURES}/templates"]
28
25
  end
29
26
 
30
- it "should find all the templates" do
31
- @gen.templates['test'].should_not be_nil
32
- @gen.templates['ejs'].should_not be_nil
27
+ it 'should find all the templates' do
28
+ @gen.templates['test_template_one'].should_not be_nil
29
+ @gen.templates['test_template_two'].should_not be_nil
33
30
  end
34
31
 
35
32
  it 'should render a template' do
36
- @gen.render_template('test').should == File.open("#{FIXTURES}/test_template.js").read
33
+ @gen.render_template('test_template_one').should == File.open("#{FIXTURES}/templates/test_template_one.js").read
34
+ @gen.render_template('test_template_two').should == File.open("#{FIXTURES}/test_template_two.js").read
37
35
  end
38
36
 
39
37
  it 'should render a template with options' do
40
- @gen.render_template('test', optional_variable: 'true').should == File.open("#{FIXTURES}/test_template_options.js").read
38
+ @gen.render_template('test_template_two', optional_variable: 'true').should == File.open("#{FIXTURES}/test_template_options.js").read
41
39
  end
42
40
 
43
- it 'should render templates with different file extensions' do
44
- @gen.templates['ejs'].is_a?(ERB).should be_true
45
- @gen.render_template('ejs').should == File.open("#{FIXTURES}/test_template.js").read
46
- @gen.render_template('ejs', optional_variable: 'true').should == File.open("#{FIXTURES}/test_template_options.js").read
41
+ it 'should generate a file from a template' do
42
+ @gen.generate_file("test.js", @gen.render_template("test_template_two"), TMP_DIR)
43
+ File.exists?("#{TMP_DIR}/test.js").should be_true
44
+ File.open("#{TMP_DIR}/test.js").read.should == File.open("#{FIXTURES}/test_template_two.js").read
47
45
  end
48
-
49
46
  end
data/spec/project_spec.rb CHANGED
@@ -14,14 +14,14 @@ describe ArchitectureJS::Project do
14
14
  end
15
15
  end
16
16
 
17
- it "should add the 'none' framework to ArchitectureJS" do
18
- ArchitectureJS::FRAMEWORKS['none'].should == ArchitectureJS::Project
19
- end
20
-
21
17
  after :each do
22
18
  FileUtils.rm_rf "#{TMP_DIR}" if File.exists? "#{TMP_DIR}"
23
19
  end
24
20
 
21
+ it "should add the 'none' framework to ArchitectureJS" do
22
+ ArchitectureJS::FRAMEWORKS['none'].should == ArchitectureJS::Project
23
+ end
24
+
25
25
  it 'should have an empty src_files array' do
26
26
  @project.src_files.should == Array.new
27
27
  end
@@ -49,9 +49,22 @@ describe ArchitectureJS::Project do
49
49
  it "should have a generator" do
50
50
  @project.generator.should_not be_nil
51
51
  end
52
+
53
+ context "with existing project" do
54
+ before(:each) do
55
+ FileUtils.cp("#{FIXTURES}/myapp.architecture", "#{TMP_DIR}/myapp.architecture")
56
+ end
57
+
58
+ it "should initialize with a config path" do
59
+ @existing = ArchitectureJS::Project.new_from_config TMP_DIR
60
+ @existing.config.should_not be_empty
61
+ @existing.config[:name].should == 'myapp'
62
+ end
63
+
64
+ end
52
65
  end # Instantiation
53
66
 
54
- context "Project Creation" do
67
+ context "- Creation -" do
55
68
  before :each do
56
69
  FileUtils.mkdir("#{TMP_DIR}")
57
70
  suppress_output do
@@ -79,7 +92,7 @@ describe ArchitectureJS::Project do
79
92
  end
80
93
  end # Project Creation
81
94
 
82
- context "Project Update" do
95
+ context "- Update -" do
83
96
  before :each do
84
97
  FileUtils.mkdir("#{TMP_DIR}")
85
98
  suppress_output do
@@ -98,9 +111,13 @@ describe ArchitectureJS::Project do
98
111
 
99
112
  it 'should compile the source files into the destination folder' do
100
113
  File.exists?("#{TMP_DIR}/lib/myapp.js").should be_true
101
- "#{TMP_DIR}/lib/myapp.js".should be_same_file_as "#{FIXTURES}/compiled_src.js"
114
+ "#{TMP_DIR}/lib/myapp.js".should be_same_file_as "#{FIXTURES}/compressed.js"
102
115
  end
103
116
 
117
+ it 'should compress the application file' do
118
+ FileUtils.cp "#{FIXTURES}/compressed.architecture", "#{TMP_DIR}/myapp.architecture"
119
+ @project.config[:output].should == 'compressed'
120
+ end
104
121
  end # Project Update
105
122
 
106
123
  end
File without changes
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.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-28 00:00:00.000000000Z
12
+ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fssm
16
- requirement: &70124576688560 !ruby/object:Gem::Requirement
16
+ requirement: &70184953295460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70124576688560
24
+ version_requirements: *70184953295460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jsmin
27
- requirement: &70124576688060 !ruby/object:Gem::Requirement
27
+ requirement: &70184953294860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70124576688060
35
+ version_requirements: *70184953294860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sprockets
38
- requirement: &70124576687580 !ruby/object:Gem::Requirement
38
+ requirement: &70184953294260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70124576687580
46
+ version_requirements: *70184953294260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70124576663800 !ruby/object:Gem::Requirement
49
+ requirement: &70184953293520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70124576663800
57
+ version_requirements: *70184953293520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70124576663220 !ruby/object:Gem::Requirement
60
+ requirement: &70184953292980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.5.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70124576663220
68
+ version_requirements: *70184953292980
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: shoulda
71
- requirement: &70124576662580 !ruby/object:Gem::Requirement
71
+ requirement: &70184953292400 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70124576662580
79
+ version_requirements: *70184953292400
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rcov
82
- requirement: &70124576661980 !ruby/object:Gem::Requirement
82
+ requirement: &70184953291780 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70124576661980
90
+ version_requirements: *70184953291780
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &70124576661420 !ruby/object:Gem::Requirement
93
+ requirement: &70184953291140 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 2.3.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70124576661420
101
+ version_requirements: *70184953291140
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ZenTest
104
- requirement: &70124576660940 !ruby/object:Gem::Requirement
104
+ requirement: &70184953290540 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 4.4.2
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70124576660940
112
+ version_requirements: *70184953290540
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rdoc
115
- requirement: &70124576660380 !ruby/object:Gem::Requirement
115
+ requirement: &70184953289940 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70124576660380
123
+ version_requirements: *70184953289940
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: jsmin
126
- requirement: &70124576659900 !ruby/object:Gem::Requirement
126
+ requirement: &70184953289340 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70124576659900
134
+ version_requirements: *70184953289340
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: fssm
137
- requirement: &70124576659420 !ruby/object:Gem::Requirement
137
+ requirement: &70184953288740 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *70124576659420
145
+ version_requirements: *70184953288740
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: sprockets
148
- requirement: &70124576658940 !ruby/object:Gem::Requirement
148
+ requirement: &70184953288140 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - =
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: 1.0.2
154
154
  type: :runtime
155
155
  prerelease: false
156
- version_requirements: *70124576658940
156
+ version_requirements: *70184953288140
157
157
  description: Architecture.js helps you generate scaffolding, manage third-party packages,
158
158
  compile, and compress your application.
159
159
  email: daytonn@gmail.com
@@ -166,6 +166,7 @@ extra_rdoc_files:
166
166
  files:
167
167
  - .DS_Store
168
168
  - .document
169
+ - .travis.yml
169
170
  - Gemfile
170
171
  - Gemfile.lock
171
172
  - LICENSE.txt
@@ -175,6 +176,7 @@ files:
175
176
  - architecture-js.gemspec
176
177
  - bin/architect
177
178
  - lib/architecture-js.rb
179
+ - lib/architecture-js/architect.rb
178
180
  - lib/architecture-js/command.rb
179
181
  - lib/architecture-js/dependencies.rb
180
182
  - lib/architecture-js/generator.rb
@@ -185,21 +187,26 @@ files:
185
187
  - spec/architecture-js_spec.rb
186
188
  - spec/cli_spec.rb
187
189
  - spec/command_spec.rb
190
+ - spec/fixtures/.DS_Store
188
191
  - spec/fixtures/compiled_src.js
189
- - spec/fixtures/ejs_template.ejs
192
+ - spec/fixtures/compressed.architecture
193
+ - spec/fixtures/compressed.js
194
+ - spec/fixtures/ejs.ejs
190
195
  - spec/fixtures/existing.architecture
191
196
  - spec/fixtures/lib1.js
192
197
  - spec/fixtures/lib2.js
193
198
  - spec/fixtures/myapp.architecture
194
199
  - spec/fixtures/src_file.js
195
- - spec/fixtures/test_template.erb
196
- - spec/fixtures/test_template.js
200
+ - spec/fixtures/templates/test_template_one.js
201
+ - spec/fixtures/templates/test_template_two.js
197
202
  - spec/fixtures/test_template_options.js
203
+ - spec/fixtures/test_template_two.js
198
204
  - spec/generator_spec.rb
199
205
  - spec/helpers_spec.rb
200
206
  - spec/notification_spec.rb
201
207
  - spec/project_spec.rb
202
208
  - spec/spec_helper.rb
209
+ - templates/blank.js
203
210
  homepage: http://github.com/daytonn/architecture.js
204
211
  licenses:
205
212
  - MIT
@@ -215,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
222
  version: '0'
216
223
  segments:
217
224
  - 0
218
- hash: 3666074057750584530
225
+ hash: 1367257639939266064
219
226
  required_rubygems_version: !ruby/object:Gem::Requirement
220
227
  none: false
221
228
  requirements: