ninjs 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/Gemfile +1 -3
  2. data/Gemfile.lock +1 -67
  3. data/README.md +348 -0
  4. data/Rakefile +2 -4
  5. data/VERSION +1 -1
  6. data/bin/ninjs +196 -39
  7. data/lib/ninjs/command.rb +23 -64
  8. data/lib/ninjs/configuration.rb +16 -38
  9. data/lib/ninjs/generator.rb +23 -12
  10. data/lib/ninjs/project.rb +7 -6
  11. data/ninjs.gemspec +9 -33
  12. data/repository/ninjs/core/module.js +32 -105
  13. data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
  14. data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
  15. data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
  16. data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
  17. data/repository/ninjs/extensions/ninjs.jquery.js +67 -0
  18. metadata +74 -100
  19. data/README.textile +0 -287
  20. data/tmp/metric_fu/output/churn.html +0 -692
  21. data/tmp/metric_fu/output/flay.html +0 -566
  22. data/tmp/metric_fu/output/flay.js +0 -11
  23. data/tmp/metric_fu/output/flog.html +0 -2392
  24. data/tmp/metric_fu/output/flog.js +0 -12
  25. data/tmp/metric_fu/output/hotspots.html +0 -3607
  26. data/tmp/metric_fu/output/index.html +0 -572
  27. data/tmp/metric_fu/output/lib_ninjs.rb.html +0 -49
  28. data/tmp/metric_fu/output/lib_ninjs_command.rb.html +0 -137
  29. data/tmp/metric_fu/output/lib_ninjs_configuration.rb.html +0 -107
  30. data/tmp/metric_fu/output/lib_ninjs_project.rb.html +0 -236
  31. data/tmp/metric_fu/output/rcov.html +0 -566
  32. data/tmp/metric_fu/output/rcov.js +0 -11
  33. data/tmp/metric_fu/output/reek.html +0 -1294
  34. data/tmp/metric_fu/output/reek.js +0 -20
  35. data/tmp/metric_fu/output/roodi.html +0 -599
  36. data/tmp/metric_fu/output/roodi.js +0 -11
  37. data/tmp/metric_fu/report.yml +0 -1548
data/Rakefile CHANGED
@@ -54,10 +54,8 @@ namespace :ndoc do
54
54
  desc "Generate documentation with NaturalDocs"
55
55
 
56
56
  task :generate do
57
- output = `ndocs -i /Volumes/Storage/Development/ninjs/repository/ninjs/ -o HTML /Volumes/Storage/Development/ninjs-ghpages/repository/ninjs/docs -p /Volumes/Storage/Development/ninjs-ghpages/repository/ninjs/docs` # -s Slick
57
+ output = `ndocs -i /Volumes/Storage/Development/ninjs/repository/ninjs/ -o HTML /Volumes/Storage/Development/ninjs-ghpages/docs -p /Volumes/Storage/Development/ninjs-ghpages/docs` # -s Slick
58
58
  puts output
59
59
  end
60
60
 
61
- end
62
-
63
- require 'metric_fu'
61
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.1
1
+ 0.13.2
data/bin/ninjs CHANGED
@@ -3,62 +3,219 @@
3
3
  $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
4
4
 
5
5
  begin
6
- require 'rubikon'
7
6
  require 'ninjs'
7
+ require 'optparse'
8
8
  rescue LoadError
9
9
  require 'rubygems'
10
- require 'rubikon'
11
10
  require 'ninjs'
11
+ require 'optparse'
12
12
  end
13
13
 
14
- class NinjsConsole < Rubikon::Application::Base
15
- def initialize
16
- @directory = '/'
17
- end
14
+ header = <<-HEADER
15
+ ninjs #{Ninjs::VERSION}
16
+ Copyright (c) #{Time.new.year} Dayton Nolan
17
+ Released under the MIT License
18
+
19
+ Description:
20
+ The ninjs command line application is a simple way to quickly develop and manage your application. With it you can create an application, generate scaffolding, compile, and upgrade your application.
21
+
22
+ Usage: ninjs [command] [arguments] [options (-h, --help)]
23
+
24
+ Commands:
25
+ HEADER
26
+
27
+ create = <<-CREATE
28
+ create Creates a new ninjs application in the current working
29
+ directory or sub directory within.
30
+
31
+ Arguments:
32
+ application name - Name of the ninjs application
33
+ subdirectory* - Directory where the application will be
34
+ installed (created if non existent)
35
+
36
+ examples:
37
+ ninjs create myapp
38
+ ninjs create myapp subdirectory
39
+ CREATE
40
+
41
+ generate = <<-GEN
42
+ generate Generates scoffolding for the given component file type.
43
+
44
+ Arguments:
45
+ type - Type of application scaffold to create (module, elements, model).
46
+ name* - Name of the module to generate the scaffold for
47
+
48
+ Options:
49
+ -a, --alias name* - Create an alias of the application object
50
+ (defaults to "app"), passing a name is optional
51
+ -e, --elements - Generate an elements file
52
+ -m, --model - Generate a model file
53
+
54
+ examples:
55
+ ninjs generate module mymodule -em (generates module, elements and model)
56
+ ninjs generate module mymodule -a (generates an application alias)
57
+ ninjs generate elements mymodule -m (generates an elements and a model file)
58
+ ninjs generate model mymodule (generates an model file)
59
+ GEN
60
+
61
+ compile = <<-COMP
62
+ compile Compiles the ninjs project in the current working directory.
18
63
 
19
- flag :v => :version
20
- option :version
21
- default do
22
- if version.given?
23
- time = Time.now
24
- Ninjs::Notification.notice 'ninjs ' + Ninjs::VERSION
25
- Ninjs::Notification.notice "Copyright (c) #{time.year} Dayton Nolan"
26
- Ninjs::Notification.notice "Released under the MIT License"
27
- else
28
- Ninjs::Command.help
64
+ Options:
65
+ -c, --compress - Compress output with JsMin
66
+
67
+ example:
68
+ ninjs compile
69
+ COMP
70
+
71
+ watch = <<-WATCH
72
+ watch Watches the current working directory for file changes and
73
+ compiles when changes are detected.
74
+
75
+ example:
76
+ ninjs watch
77
+ WATCH
78
+
79
+ upd = <<-UPDATE
80
+ update Updates your application's core files to the latest version.
81
+ UPDATE
82
+
83
+ footer = <<-FOOTER
84
+ * optional argument
85
+ FOOTER
86
+
87
+ help = {
88
+ :header => header,
89
+ :create => create,
90
+ :generate => generate,
91
+ :compile => compile,
92
+ :watch => watch,
93
+ :update => upd,
94
+ :footer => footer
95
+ }
96
+
97
+ command = ARGV[0]
98
+
99
+ options = {
100
+ :alias => false,
101
+ :elements => false,
102
+ :model => false,
103
+ :help => false,
104
+ :compress => false
105
+ }
106
+
107
+ optparse = OptionParser.new do|opts|
108
+ opts.on( '-h', '--help', 'Display this screen' ) do
109
+ options[:help] = true
110
+
111
+ if command.nil? || command.match(/^-h/)
112
+ help.each do |section|
113
+ puts section
114
+ end
115
+ exit
29
116
  end
30
117
  end
31
118
 
32
- command :compile do
33
- Ninjs::Command.compile
119
+ opts.on( '-v', '--version', 'Display the version') do
120
+ time = Time.now
121
+ Ninjs::Notification.notice 'ninjs ' + Ninjs::VERSION
122
+ Ninjs::Notification.notice "Copyright (c) #{time.year} Dayton Nolan"
123
+ Ninjs::Notification.notice "Released under the MIT License"
124
+ exit
34
125
  end
35
126
 
36
- command :watch do
37
- Ninjs::Command.watch
127
+ opts.on( '-a', '--alias', 'Generate application alias') do
128
+ options[:alias] = true
38
129
  end
39
130
 
40
- command :import do
41
- Ninjs::Command.import
131
+ opts.on('-e', '--elements', 'Generate elements file') do
132
+ options[:elements] = true
42
133
  end
43
134
 
44
- command :create, :app_name, :dir => :optional do
45
- dir.nil? ? Ninjs::Command.create(app_name) : Ninjs::Command.create(app_name, dir)
135
+ opts.on('-m', '--model', 'Generate model file') do
136
+ options[:model] = true
46
137
  end
138
+
139
+ opts.on('-c', '--compress', 'Compress with JsMin') do
140
+ options[:compress] = true
141
+ end
142
+ end
47
143
 
48
- option :elements
49
- option :model
50
- flag :e => :elements
51
- flag :m => :model
52
- command :generate, :object, :obj_name do
144
+ optparse.parse!
145
+
146
+ case command
147
+ # create
148
+ when "create"
149
+ if options[:help]
150
+ puts help[:create]
151
+ exit
152
+ end
153
+ app_name = ARGV[1]
154
+ sub_dir = ARGV[2] || nil
155
+
156
+ if app_name.nil?
157
+ puts "Error! Application name is required (ninjs create app_name)"
158
+ exit
159
+ end
160
+
161
+ sub_dir.nil? ? Ninjs::Command.create(app_name) : Ninjs::Command.create(app_name, sub_dir)
162
+ # generate
163
+ when "generate"
164
+ if options[:help]
165
+ puts help[:generate]
166
+ exit
167
+ end
168
+ errors = Hash.new
169
+ type = ARGV[1]
170
+ name = ARGV[2]
171
+ als = ARGV[3] || 'app'
172
+
173
+ errors[:type] = "Error! Scaffold type is required (ninjs generate module mymodule)" if type.nil?
174
+ errors[:name] = "Error! Module name is required (ninjs generate module mymodule)" if name.nil?
175
+
176
+ unless errors.empty?
177
+ errors.each do |error|
178
+ puts error
179
+ end
180
+ exit
181
+ end
182
+
53
183
  with = {
54
- :model => model.given?,
55
- :elements => elements.given?
184
+ :model => options[:model],
185
+ :elements => options[:elements]
56
186
  }
57
-
58
- Ninjs::Command.generate(object, obj_name, with)
59
- end
60
-
61
- command :upgrade do
62
- Ninjs::Command.upgrade
63
- end
64
- end
187
+
188
+ if options[:alias]
189
+ Ninjs::Command.generate_with_alias(type, name, with, als)
190
+ else
191
+ Ninjs::Command.generate(type, name, with)
192
+ end
193
+ # compile
194
+ when "compile"
195
+ if options[:help]
196
+ puts help[:compile]
197
+ exit
198
+ end
199
+
200
+ compress_output = options[:compress] ? true : false
201
+ Ninjs::Command.compile(compress_output)
202
+ # watch
203
+ when "watch"
204
+ if options[:help]
205
+ puts help[:watch]
206
+ exit
207
+ end
208
+ Ninjs::Command.watch
209
+ # update
210
+ when "update"
211
+ if options[:help]
212
+ puts help[:update]
213
+ exit
214
+ end
215
+ Ninjs::Command.update
216
+ # help
217
+ else
218
+ help.each do |section|
219
+ puts section
220
+ end
221
+ end
@@ -48,81 +48,40 @@ module Ninjs
48
48
  project.create
49
49
  end
50
50
 
51
- def compile
51
+ def compile(compress_output)
52
52
  project_path = Dir.getwd << '/'
53
53
  raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
54
54
  project = Ninjs::Project.new
55
+ project.config.output = compress_output ? 'compressed' : 'expanded'
55
56
  project.update
56
57
  end
57
58
 
58
59
  def import(package)
59
60
  Ninjs::PackageManager.import(package)
60
61
  end
61
-
62
- def help
63
- puts <<-DOC
64
- ninjs #{Ninjs::VERSION}
65
- Copyright (c) #{Time.new.year} Dayton Nolan
66
- Released under the MIT License
67
-
68
- Description:
69
- The ninjs command line application is a simple way to quickly develop and manage your application. With it you can create an application, generate scaffolding, compile, and upgrade your application.
70
-
71
- Usage: ninjs [command] [arguments]
72
-
73
- Commands:
74
- create Creates a new ninjs application in the current working
75
- directory or sub directory within.
76
-
77
- Arguments:
78
- application name - Name of the ninjs application
79
- sub directory* - Directory where the application will be
80
- installed (created if non existent)
81
-
82
- examples:
83
- ninjs create myapp
84
- ninjs create myapp subdirectory
85
-
86
- generate Generates scoffolding for the given component file type.
87
-
88
- Arguments:
89
- file type - Type of application file to create (module, elements,
90
- model).
91
- module name* - Name of the module to generate the scaffold for
92
-
93
- Flags:
94
- -e - Generate an elements file for the same module
95
- -m - Generate a model file for the same module
96
-
97
- examples:
98
- ninjs generate model mymodule -e -m
99
- ninjs generate elements mymodule
100
- ninjs generate model mymodule
101
-
102
- compile Compiles the ninjs project in the current working directory.
103
-
104
- example:
105
- ninjs compile
106
-
107
- watch Watches the current working directory for file changes and
108
- compiles when changes are detected.
109
-
110
- example:
111
- ninjs watch
112
-
113
- upgrade Upgrades your application's core files to the latest version.
114
-
115
- * optional argument
116
- DOC
117
- end
118
62
 
119
63
  def generate(object, name, with)
120
64
  begin
121
65
  conf_path = "#{Dir.getwd}/ninjs.conf"
122
66
  raise "ninjs.conf was not located in #{conf_path}" unless File.exists? "#{conf_path}"
123
67
  generator = Ninjs::Generator.new(Ninjs::Project.new, name)
124
-
125
- case object
68
+ self.generate_object generator, object, with
69
+ end
70
+ end
71
+
72
+ def generate_with_alias(object, name, with, als = 'app')
73
+ begin
74
+ conf_path = "#{Dir.getwd}/ninjs.conf"
75
+ raise "ninjs.conf was not located in #{conf_path}" unless File.exists? "#{conf_path}"
76
+ generator = Ninjs::Generator.new(Ninjs::Project.new, name)
77
+ generator.alias = true
78
+ generator.app_name = als
79
+ self.generate_object generator, object, with
80
+ end
81
+ end
82
+
83
+ def generate_object(generator, object, with)
84
+ case object
126
85
  when 'module'
127
86
  generator.generate_module_file(with)
128
87
  generator.generate_elements_file if with[:elements]
@@ -131,18 +90,18 @@ Commands:
131
90
  generator.generate_elements_file
132
91
  when 'model'
133
92
  generator.generate_model_file
134
- end #case
135
- end
93
+ end
136
94
  end
137
95
 
138
- def upgrade
96
+ def update
139
97
  project_path = Dir.getwd << '/'
140
98
  raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}ninjs.conf"
141
99
  project = Ninjs::Project.new
142
100
 
143
101
  project.create_ninjs_lib_file
102
+ project.create_utility_lib_file
144
103
  end
145
104
 
146
- module_function :create, :watch, :compile, :help, :import, :generate, :upgrade
105
+ module_function :create, :watch, :compile, :import, :generate, :generate_object, :generate_with_alias, :update
147
106
  end
148
107
  end
@@ -2,27 +2,23 @@ module Ninjs
2
2
  class Configuration
3
3
 
4
4
  attr_reader :name,
5
- :app_filename,
6
- :directory,
7
- :output,
8
5
  :dependencies,
9
6
  :autoload,
10
- :config_path,
11
- :asset_root,
12
- :base_url,
13
- :test_path
7
+ :asset_root
8
+
9
+ attr_accessor :output
14
10
 
15
11
  def initialize(project_path, name = '')
16
12
  @project_path = project_path
13
+
17
14
  @defaults = {
18
15
  :name => name,
19
- :app_filename => name.gsub(/\s|\-|\./, '').downcase,
20
16
  :output => 'expanded',
21
- :dependencies => ['<jquery/latest>'],
22
- :autoload => ['<ninjs/utilities/all>'],
23
- :base_url => 'http://www.example.com/',
24
- :test_path => 'tests/'
17
+ :dependencies => ['"<jquery/latest>"'],
18
+ :autoload => ['"../lib/utilities"']
25
19
  }
20
+
21
+ @asset_root = @project_path
26
22
 
27
23
  @defaults.each do |label, setting|
28
24
  instance_variable_set("@#{label}", setting)
@@ -34,16 +30,14 @@ module Ninjs
34
30
  end
35
31
 
36
32
  def create
37
- options = @defaults
38
- options.delete :app_filename
39
- default_content = conf_content options
40
- create_conf_file default_content
33
+ create_conf_file conf_content(@defaults)
41
34
  end
42
35
 
43
36
  def conf_content(options)
44
37
  content = String.new
45
38
  options.each do |option, value|
46
- content << "#{option}: #{value}\n"
39
+ content << "#{option}: #{value}\n" if value.kind_of? String
40
+ content << "#{option}: [#{value.join(', ')}]\n" if value.kind_of? Array
47
41
  end
48
42
  content
49
43
  end
@@ -55,33 +49,17 @@ module Ninjs
55
49
 
56
50
  Ninjs::Notification.notify "ninjs.conf created", :added
57
51
  end
58
-
59
- def update
60
- options = {
61
- :name => @name,
62
- :asset_root => @asset_root,
63
- :output => @output,
64
- :dependencies => @dependencies,
65
- :autoload => @autoload,
66
- :base_url => @base_url,
67
- :test_path => @test_path
68
- }
69
- options.reject! { |option| option.nil? }
70
-
71
- content = conf_content options
72
- create_conf_file content
73
- end
74
-
52
+
75
53
  def read
76
54
  config = YAML.load_file("#{@project_path}ninjs.conf")
77
- @asset_root = config['asset_root'] unless config['asset_root'].nil?
55
+
78
56
  @name = config['name']
79
- @app_filename = config['name'].downcase
80
57
  @output = config['output']
58
+
81
59
  @dependencies = config['dependencies'] || Array.new
82
60
  @autoload = config['autoload'] || Array.new
83
- @base_url = config['base_url'] || 'http://www.example.com/'
84
- @test_path = config['test_path'] || 'tests/'
61
+
62
+ @asset_root = config['asset_root'] unless config['ass'].nil?
85
63
  end
86
64
 
87
65
  end