ninjs 0.14.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/.bundle/config +2 -2
  2. data/.travis.yml +1 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +13 -11
  5. data/README.md +108 -93
  6. data/Rakefile +17 -7
  7. data/VERSION +1 -1
  8. data/bin/ninjs +24 -22
  9. data/lib/ninjs/command.rb +32 -21
  10. data/lib/ninjs/configuration.rb +35 -53
  11. data/lib/ninjs/generator.rb +6 -6
  12. data/lib/ninjs/notification.rb +5 -5
  13. data/lib/ninjs/project.rb +31 -25
  14. data/ninjs.gemspec +18 -142
  15. data/repository/ninjs/core/application.js +13 -24
  16. data/repository/ninjs/core/dom.js +87 -68
  17. data/repository/ninjs/core/existence.js +44 -105
  18. data/repository/ninjs/core/extend.js +11 -32
  19. data/repository/ninjs/core/module.js +53 -107
  20. data/repository/ninjs/core/nin.js +5 -7
  21. data/repository/ninjs/tests/extension.test.js +0 -10
  22. data/repository/ninjs/tests/index.html +19 -20
  23. data/repository/ninjs/tests/module.test.js +52 -56
  24. data/repository/ninjs/utilities/array.js +8 -8
  25. data/repository/ninjs/utilities/cookie.js +59 -0
  26. data/repository/ninjs/utilities/css.js +7 -7
  27. data/repository/ninjs/utilities/number.js +2 -2
  28. data/repository/ninjs/utilities/string.js +26 -26
  29. data/spec/cli_spec.rb +90 -88
  30. data/spec/command_spec.rb +104 -137
  31. data/spec/configuration_spec.rb +23 -37
  32. data/spec/fixtures/_global.module.js +9 -0
  33. data/spec/fixtures/compressed.myapp.js +23 -44
  34. data/spec/fixtures/foo.elements.js +1 -1
  35. data/spec/fixtures/foo.js +5 -5
  36. data/spec/fixtures/foo.model.js +1 -1
  37. data/spec/fixtures/foo.module.js +3 -3
  38. data/spec/fixtures/hello.elements.js +1 -1
  39. data/spec/fixtures/hello.js +5 -5
  40. data/spec/fixtures/hello.model.js +1 -1
  41. data/spec/fixtures/hello.module.js +3 -3
  42. data/spec/fixtures/myapp.initial.js +198 -329
  43. data/spec/fixtures/myapp.js +285 -357
  44. data/spec/fixtures/mymodule.alias.module.js +2 -2
  45. data/spec/fixtures/mymodule.dependencies.module.js +2 -2
  46. data/spec/fixtures/mymodule.elements.js +1 -1
  47. data/spec/fixtures/mymodule.model.js +1 -1
  48. data/spec/fixtures/mymodule.module.js +2 -2
  49. data/spec/fixtures/mymodule.module_alias.module.js +10 -0
  50. data/spec/fixtures/new.ninjs.conf +2 -0
  51. data/spec/fixtures/nin.js +198 -329
  52. data/spec/fixtures/ninjs.conf +2 -0
  53. data/spec/fixtures/updated.ninjs.conf +8 -0
  54. data/spec/generator_spec.rb +37 -26
  55. data/spec/ninjs_spec.rb +6 -6
  56. data/spec/project_spec.rb +229 -221
  57. data/spec/spec_helper.rb +3 -1
  58. data/spec/testspec_spec.rb +7 -0
  59. metadata +28 -145
  60. data/repository/json2.js +0 -482
  61. data/repository/modernizr/1.5.js +0 -28
  62. data/repository/modernizr/latest.js +0 -1
  63. data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
  64. data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
  65. data/repository/ninjs/docs/Data/FileInfo.nd +0 -16
  66. data/repository/ninjs/docs/Data/ImageFileInfo.nd +0 -0
  67. data/repository/ninjs/docs/Data/ImageReferenceTable.nd +0 -0
  68. data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
  69. data/repository/ninjs/docs/Data/PreviousMenuState.nd +0 -0
  70. data/repository/ninjs/docs/Data/PreviousSettings.nd +0 -0
  71. data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
  72. data/repository/ninjs/docs/Languages.txt +0 -113
  73. data/repository/ninjs/docs/Menu.txt +0 -63
  74. data/repository/ninjs/docs/Topics.txt +0 -81
  75. data/repository/ninjs/docs/files/core/application-js.html +0 -44
  76. data/repository/ninjs/docs/files/core/existence-js.html +0 -60
  77. data/repository/ninjs/docs/files/core/extend-js.html +0 -55
  78. data/repository/ninjs/docs/files/core/module-js.html +0 -80
  79. data/repository/ninjs/docs/files/core/nin-js.html +0 -38
  80. data/repository/ninjs/docs/index.html +0 -1
  81. data/repository/ninjs/docs/index/Classes.html +0 -33
  82. data/repository/ninjs/docs/index/Files.html +0 -45
  83. data/repository/ninjs/docs/index/Functions.html +0 -65
  84. data/repository/ninjs/docs/index/General.html +0 -85
  85. data/repository/ninjs/docs/index/Variables.html +0 -45
  86. data/repository/ninjs/docs/javascript/main.js +0 -841
  87. data/repository/ninjs/docs/javascript/prettify.js +0 -1526
  88. data/repository/ninjs/docs/javascript/searchdata.js +0 -152
  89. data/repository/ninjs/docs/search/ClassesN.html +0 -20
  90. data/repository/ninjs/docs/search/FilesA.html +0 -20
  91. data/repository/ninjs/docs/search/FilesE.html +0 -20
  92. data/repository/ninjs/docs/search/FilesM.html +0 -20
  93. data/repository/ninjs/docs/search/FilesN.html +0 -20
  94. data/repository/ninjs/docs/search/FunctionsA.html +0 -20
  95. data/repository/ninjs/docs/search/FunctionsC.html +0 -20
  96. data/repository/ninjs/docs/search/FunctionsE.html +0 -20
  97. data/repository/ninjs/docs/search/FunctionsI.html +0 -20
  98. data/repository/ninjs/docs/search/FunctionsM.html +0 -20
  99. data/repository/ninjs/docs/search/FunctionsR.html +0 -20
  100. data/repository/ninjs/docs/search/FunctionsS.html +0 -20
  101. data/repository/ninjs/docs/search/FunctionsSymbols.html +0 -20
  102. data/repository/ninjs/docs/search/FunctionsU.html +0 -20
  103. data/repository/ninjs/docs/search/GeneralA.html +0 -20
  104. data/repository/ninjs/docs/search/GeneralC.html +0 -20
  105. data/repository/ninjs/docs/search/GeneralD.html +0 -20
  106. data/repository/ninjs/docs/search/GeneralE.html +0 -20
  107. data/repository/ninjs/docs/search/GeneralF.html +0 -20
  108. data/repository/ninjs/docs/search/GeneralI.html +0 -20
  109. data/repository/ninjs/docs/search/GeneralM.html +0 -20
  110. data/repository/ninjs/docs/search/GeneralN.html +0 -20
  111. data/repository/ninjs/docs/search/GeneralR.html +0 -20
  112. data/repository/ninjs/docs/search/GeneralS.html +0 -20
  113. data/repository/ninjs/docs/search/GeneralSymbols.html +0 -20
  114. data/repository/ninjs/docs/search/GeneralT.html +0 -20
  115. data/repository/ninjs/docs/search/GeneralU.html +0 -20
  116. data/repository/ninjs/docs/search/GeneralV.html +0 -20
  117. data/repository/ninjs/docs/search/NoResults.html +0 -15
  118. data/repository/ninjs/docs/search/VariablesD.html +0 -20
  119. data/repository/ninjs/docs/search/VariablesN.html +0 -20
  120. data/repository/ninjs/docs/search/VariablesR.html +0 -20
  121. data/repository/ninjs/docs/search/VariablesT.html +0 -20
  122. data/repository/ninjs/docs/styles/main.css +0 -828
  123. data/repository/nullconsole.js +0 -7
  124. data/repository/qunit/assets/css/qunit.css +0 -196
  125. data/repository/qunit/qunit.js +0 -1374
  126. data/repository/selectivizr/1.0.js +0 -5
  127. data/repository/selectivizr/latest.js +0 -1
  128. data/repository/syntaxhighlighter/all.js +0 -11
  129. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCore.css +0 -226
  130. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDefault.css +0 -328
  131. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDjango.css +0 -331
  132. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEclipse.css +0 -339
  133. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEmacs.css +0 -324
  134. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  135. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMDUltra.css +0 -324
  136. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMidnight.css +0 -324
  137. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreRDark.css +0 -324
  138. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDefault.css +0 -117
  139. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDjango.css +0 -120
  140. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEclipse.css +0 -128
  141. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEmacs.css +0 -113
  142. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  143. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMDUltra.css +0 -113
  144. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMidnight.css +0 -113
  145. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeRDark.css +0 -113
  146. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCore.scss +0 -216
  147. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDefault.scss +0 -2
  148. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDjango.scss +0 -2
  149. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEclipse.scss +0 -2
  150. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEmacs.scss +0 -2
  151. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreFadeToGrey.scss +0 -2
  152. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMDUltra.scss +0 -2
  153. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMidnight.scss +0 -2
  154. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreRDark.scss +0 -2
  155. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDefault.scss +0 -7
  156. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDjango.scss +0 -36
  157. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEclipse.scss +0 -48
  158. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEmacs.scss +0 -32
  159. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeFadeToGrey.scss +0 -36
  160. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMDUltra.scss +0 -32
  161. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMidnight.scss +0 -32
  162. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeRDark.scss +0 -32
  163. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_theme_template.scss +0 -120
  164. data/repository/syntaxhighlighter/shAutoloader.js +0 -17
  165. data/repository/syntaxhighlighter/shBrushAS3.js +0 -59
  166. data/repository/syntaxhighlighter/shBrushAppleScript.js +0 -75
  167. data/repository/syntaxhighlighter/shBrushBash.js +0 -59
  168. data/repository/syntaxhighlighter/shBrushCSharp.js +0 -65
  169. data/repository/syntaxhighlighter/shBrushColdFusion.js +0 -100
  170. data/repository/syntaxhighlighter/shBrushCpp.js +0 -97
  171. data/repository/syntaxhighlighter/shBrushCss.js +0 -91
  172. data/repository/syntaxhighlighter/shBrushDelphi.js +0 -55
  173. data/repository/syntaxhighlighter/shBrushDiff.js +0 -41
  174. data/repository/syntaxhighlighter/shBrushErlang.js +0 -52
  175. data/repository/syntaxhighlighter/shBrushGroovy.js +0 -67
  176. data/repository/syntaxhighlighter/shBrushJScript.js +0 -52
  177. data/repository/syntaxhighlighter/shBrushJava.js +0 -57
  178. data/repository/syntaxhighlighter/shBrushJavaFX.js +0 -58
  179. data/repository/syntaxhighlighter/shBrushPerl.js +0 -72
  180. data/repository/syntaxhighlighter/shBrushPhp.js +0 -88
  181. data/repository/syntaxhighlighter/shBrushPlain.js +0 -33
  182. data/repository/syntaxhighlighter/shBrushPowerShell.js +0 -74
  183. data/repository/syntaxhighlighter/shBrushPython.js +0 -64
  184. data/repository/syntaxhighlighter/shBrushRuby.js +0 -55
  185. data/repository/syntaxhighlighter/shBrushSass.js +0 -94
  186. data/repository/syntaxhighlighter/shBrushScala.js +0 -51
  187. data/repository/syntaxhighlighter/shBrushSql.js +0 -66
  188. data/repository/syntaxhighlighter/shBrushVb.js +0 -56
  189. data/repository/syntaxhighlighter/shBrushXml.js +0 -69
  190. data/repository/syntaxhighlighter/shCore.js +0 -17
  191. data/repository/syntaxhighlighter/shLegacy.js +0 -17
data/Rakefile CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'rake'
4
+ require 'jeweler'
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+ require 'rdoc/task'
8
+
3
9
  begin
4
10
  Bundler.setup(:default, :development)
5
11
  rescue Bundler::BundlerError => e
@@ -7,9 +13,7 @@ rescue Bundler::BundlerError => e
7
13
  $stderr.puts "Run `bundle install` to install missing gems"
8
14
  exit e.status_code
9
15
  end
10
- require 'rake'
11
16
 
12
- require 'jeweler'
13
17
  Jeweler::Tasks.new do |gem|
14
18
  gem.name = "ninjs"
15
19
  gem.homepage = "http://github.com/textnotspeech/ninjs"
@@ -25,10 +29,9 @@ Jeweler::Tasks.new do |gem|
25
29
  gem.add_runtime_dependency 'sprockets'
26
30
  gem.add_development_dependency 'rspec', '>= 0'
27
31
  end
32
+
28
33
  Jeweler::RubygemsDotOrgTasks.new
29
34
 
30
- require 'rspec/core'
31
- require 'rspec/core/rake_task'
32
35
  RSpec::Core::RakeTask.new(:spec) do |spec|
33
36
  spec.pattern = FileList['spec/**/*_spec.rb']
34
37
  end
@@ -40,8 +43,7 @@ end
40
43
 
41
44
  task :default => :spec
42
45
 
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
46
+ RDoc::Task.new do |rdoc|
45
47
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
48
 
47
49
  rdoc.rdoc_dir = 'rdoc'
@@ -58,4 +60,12 @@ namespace :ndoc do
58
60
  puts output
59
61
  end
60
62
 
61
- end
63
+ end
64
+ begin
65
+ require 'jasmine'
66
+ load 'jasmine/tasks/jasmine.rake'
67
+ rescue LoadError
68
+ task :jasmine do
69
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
70
+ end
71
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.1
1
+ 0.16.0
data/bin/ninjs CHANGED
@@ -72,22 +72,22 @@ footer = <<-FOOTER
72
72
  FOOTER
73
73
 
74
74
  help = {
75
- :create => create,
76
- :generate => generate,
77
- :compile => compile,
78
- :watch => watch,
79
- :update => upd,
80
- :footer => footer
75
+ create: create,
76
+ generate: generate,
77
+ compile: compile,
78
+ watch: watch,
79
+ update: upd,
80
+ footer: footer
81
81
  }
82
82
 
83
83
  command = ARGV[0]
84
84
 
85
85
  options = {
86
- :alias => nil,
87
- :elements => false,
88
- :model => false,
89
- :help => false,
90
- :compress => nil
86
+ alias: nil,
87
+ elements: false,
88
+ model: false,
89
+ help: false,
90
+ compress: nil
91
91
  }
92
92
 
93
93
  optparse = OptionParser.new do |opts|
@@ -141,7 +141,9 @@ case command
141
141
  exit
142
142
  end
143
143
 
144
- Ninjs::Command.create({ :name => app_name, :directory => sub_dir })
144
+ config = { name: app_name }
145
+ config[:root] = sub_dir unless sub_dir.nil?
146
+ Ninjs::Command.create(config)
145
147
  # generate
146
148
  when "generate"
147
149
  if options[:help]
@@ -166,17 +168,17 @@ case command
166
168
  end
167
169
 
168
170
  dependencies = {
169
- :model => options[:model],
170
- :elements => options[:elements]
171
+ model: options[:model],
172
+ elements: options[:elements]
171
173
  }
172
174
 
173
175
  Ninjs::Command.generate({
174
- :project => Ninjs::Project.new,
175
- :type => type,
176
- :name => name,
177
- :alias => als,
178
- :dest => dest,
179
- :dependencies => dependencies
176
+ project: Ninjs::Project.new,
177
+ type: type,
178
+ name: name,
179
+ alias: als,
180
+ dest: dest,
181
+ dependencies: dependencies
180
182
  })
181
183
  # compile
182
184
  when "compile"
@@ -186,9 +188,9 @@ case command
186
188
  end
187
189
 
188
190
  unless options[:compress].nil?
189
- Ninjs::Command.compile(options[:compress])
191
+ Ninjs::Command.compile({ force_compress: options[:compress] })
190
192
  else
191
- Ninjs::Command.compile()
193
+ Ninjs::Command.compile
192
194
  end
193
195
  # watch
194
196
  when "watch"
data/lib/ninjs/command.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Ninjs
2
2
  module Command
3
- def watch
3
+ def watch(path = nil)
4
4
  require "fssm"
5
5
 
6
- project_path = File.expand_path Dir.getwd
7
- raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
6
+ path ||= File.expand_path(Dir.getwd)
7
+ raise "ninjs.conf was not located in #{path}" unless File.exists? "#{path}/ninjs.conf"
8
8
 
9
9
  puts Ninjs::Notification.log "Ninjs are watching for changes. Press Ctrl-C to stop."
10
10
  project = Ninjs::Project.new
@@ -14,10 +14,10 @@ module Ninjs
14
14
  watch_hash = Hash.new
15
15
 
16
16
  watch_dirs.each do |dir|
17
- watch_hash["#{project_path}/#{dir}"] = "**/*.js"
17
+ watch_hash["#{path}/#{dir}"] = "**/*.js"
18
18
  end
19
19
 
20
- watch_hash[project_path] = "**/*.conf"
20
+ watch_hash[path] = "**/*.conf"
21
21
  watch_hash["#{Ninjs::BASE_DIR}/repository"] = "**/*.js"
22
22
 
23
23
  FSSM.monitor do
@@ -45,37 +45,48 @@ module Ninjs
45
45
 
46
46
  end
47
47
 
48
- def create(config)
49
- raise 'you must specify a project name: ninjs create ProjectName' if config[:name].nil?
48
+ def create(config = nil)
49
+ settings = {
50
+ name: nil,
51
+ root: File.expand_path(Dir.getwd)
52
+ }
50
53
 
51
- project = Ninjs::Project.new config[:name]
52
- project.root = config[:directory] unless config[:directory].nil?
53
- puts project.root
54
+ settings.merge!(config) unless config.nil?
55
+
56
+ raise 'you must specify a project name: ninjs create ProjectName' if settings[:name].nil?
57
+
58
+ project = Ninjs::Project.new({ name: settings[:name], root: settings[:root] })
54
59
  project.create
55
60
  end
56
61
 
57
- def compile(force_compress = false)
58
- project_path = Dir.getwd << '/'
59
- raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
60
- project = Ninjs::Project.new
61
- project.config.output = 'compressed' if force_compress
62
+ def compile(options = nil)
63
+ settings = {
64
+ force_compress: false,
65
+ path: File.expand_path(Dir.getwd)
66
+ }
67
+
68
+ settings.merge!(options) unless options.nil?
69
+
70
+ raise "ninjs.conf was not located in #{settings[:path]}" unless File.exists? "#{settings[:path]}/ninjs.conf"
71
+ project = Ninjs::Project.new(root: settings[:path])
72
+ project.config.output = 'compressed' if settings[:force_compress]
62
73
  project.update
63
74
  end
64
75
 
65
76
  def generate(config)
66
77
  begin
67
- conf_path = "#{Dir.getwd}/ninjs.conf"
68
- raise "ninjs.conf was not located in #{conf_path}" unless File.exists? "#{conf_path}"
78
+ conf_path = "#{config[:project].root}/ninjs.conf"
79
+ raise "ninjs.conf was not located in #{conf_path}" unless File.exists? conf_path
69
80
  generator = Ninjs::Generator.new(config)
70
81
  generator.generate
71
82
  end
72
83
  end
73
84
 
74
- def update
75
- project_path = Dir.getwd << '/'
76
- raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}ninjs.conf"
85
+ def update(path = nil)
86
+ path = File.expand_path Dir.getwd if path.nil?
87
+ raise "ninjs.conf was not located in #{path}" unless File.exists? "#{path}/ninjs.conf"
77
88
 
78
- project = Ninjs::Project.new
89
+ project = Ninjs::Project.new({ root: path })
79
90
  project.create_ninjs_lib_file
80
91
  project.create_utility_lib_file
81
92
  end
@@ -1,82 +1,64 @@
1
1
  module Ninjs
2
2
  class Configuration
3
-
4
- attr_reader :path,
5
- :settings,
6
- :name,
7
- :dependencies,
8
- :autoload,
9
- :src_dir,
10
- :dest_dir
11
-
12
- attr_accessor :output,
13
- :root,
14
- :asset_root
15
-
3
+
4
+ attr_accessor :root,
5
+ :name,
6
+ :src_dir,
7
+ :dest_dir,
8
+ :asset_root,
9
+ :asset_root_relative,
10
+ :output,
11
+ :dependencies,
12
+ :autoload,
13
+ :module_alias
14
+
16
15
  def initialize(project_path)
17
16
  @root = File.expand_path project_path
18
- @settings = Hash.new
19
- @asset_root = @root
20
-
21
- setting(:name, 'application')
22
- setting(:src_dir, 'modules')
23
- setting(:dest_dir, 'application')
24
- setting(:output, 'expanded')
25
- setting(:dependencies, ['<jquery/latest>'])
26
- setting(:autoload, ['../lib/utilities'])
27
-
28
- optional_settings.each do |label, setting|
29
- setting(label, setting)
30
- end
31
-
17
+ @name = 'application'
18
+ @src_dir = 'modules'
19
+ @dest_dir = 'application'
20
+ @asset_root_relative = '../'
21
+ @asset_root = File.expand_path('../', @root)
22
+ @output = 'expanded'
23
+ @dependencies = ['<jquery/latest>']
24
+ @autoload = ['../lib/utilities']
25
+ @module_alias = 'mod'
26
+
32
27
  read if File.exists? "#{@root}/ninjs.conf"
33
28
  end
34
-
35
- def optional_settings
36
- @settings.reject do |key, value|
37
- key.to_s.match /name|src_dir|dest_dir|output|dependencies|autoload/
38
- end
39
- end
40
-
41
- def setting(name, value)
42
- instance_variable_set("@#{name}", value)
43
- @settings[name] = value
44
- end
45
-
29
+
46
30
  def write
47
31
  File.open("#{@root}/ninjs.conf", "w+") do |conf_file|
48
32
  conf_file << "name: #{@name}\n"
49
33
  conf_file << "src_dir: #{@src_dir}\n"
50
34
  conf_file << "dest_dir: #{@dest_dir}\n"
35
+ conf_file << "asset_root: #{@asset_root_relative} # relative to project root\n"
51
36
  conf_file << "output: #{@output}\n"
52
37
  conf_file << "dependencies: #{array_to_yml @dependencies}\n"
53
38
  conf_file << "autoload: #{array_to_yml @autoload}\n"
54
-
55
- optional_settings.each do |setting, value|
56
- conf_file << "setting: #{value}\n"
57
- end
39
+ conf_file << "module_alias: #{@module_alias}\n"
58
40
  end
59
-
41
+
60
42
  puts Ninjs::Notification.notify "ninjs.conf created", :added
61
43
  end
62
-
44
+
63
45
  def read
64
- config = YAML.load_file("#{@project_path}ninjs.conf")
65
-
46
+ config = YAML.load_file("#{@root}/ninjs.conf")
47
+
66
48
  @name = config['name']
67
- @output = config['output']
68
49
  @src_dir = config['src_dir']
69
50
  @dest_dir = config['dest_dir']
70
-
51
+ @asset_root_relative = config['asset_root'] || @asset_root_relative
52
+ @asset_root = File.expand_path(@asset_root_relative, @root)
53
+ @output = config['output']
71
54
  @dependencies = config['dependencies'] || Array.new
72
55
  @autoload = config['autoload'] || Array.new
73
-
74
- @asset_root = config['asset_root'] unless config['ass'].nil?
56
+ @module_alias = config['module_alias'] || 'mod'
75
57
  end
76
-
58
+
77
59
  def array_to_yml(array)
78
60
  yml = array.empty? ? '[]' : %Q{['#{array.join("', '")}']}
79
61
  end
80
-
62
+
81
63
  end
82
64
  end
@@ -11,7 +11,7 @@ module Ninjs
11
11
  @alias = config[:alias].nil? ? false : true
12
12
  @app_name = config[:alias] || @project.config.name
13
13
  @dest = config[:dest] || @project.config.src_dir.is_a?(String) ? @project.config.src_dir : @project.config.src_dir.first
14
- @dependencies = config[:dependencies] || { :elements => false, :model => false }
14
+ @dependencies = config[:dependencies] || { elements: false, model: false }
15
15
  end
16
16
 
17
17
  def generate
@@ -23,11 +23,11 @@ module Ninjs
23
23
  def generate_module_file
24
24
  module_content = Array.new
25
25
  module_content << "(function(#{@app_name if @alias}) {\n"
26
- module_content << "\tvar mod = #{@app_name}.add_module('#{@name}');\n\n"
26
+ module_content << "\tvar #{@project.config.module_alias} = #{@app_name}.add_module('#{@name}');\n\n"
27
27
  module_content << %Q{\t//= require "../elements/#{@name.downcase}.elements"\n} if @dependencies[:elements] || @type === 'elements'
28
28
  module_content << %Q{\t//= require "../models/#{@name.downcase}.model"\n\n} if @dependencies[:model] || @type === 'model'
29
- module_content << "\t#{@app_name}.#{@module_name}.actions = function() {\n\t\t\n\t};\n\n"
30
- module_content << "\t#{@app_name}.#{@module_name}.run();\n"
29
+ module_content << "\t#{@project.config.module_alias}.actions = function() {\n\t\t\n\t};\n\n"
30
+ module_content << "\t#{@project.config.module_alias}.run();\n"
31
31
  module_content << "\n})(#{@project.config.name if @alias});"
32
32
 
33
33
 
@@ -41,7 +41,7 @@ module Ninjs
41
41
 
42
42
  def generate_elements_file
43
43
  File.open("#{@project.root}/elements/#{@module_name}" + ".elements.js", "w") do |file|
44
- file << %Q{\tmod.dom.ready(function() {\n\t\t#{@app_name}.#{@module_name}.elements({\n\t\t\t\n\t\t});\n\t});\n}
44
+ file << %Q{\t#{@project.config.module_alias}.dom.ready(function() {\n\t\tmod.elements({\n\t\t\t\n\t\t});\n\t});\n}
45
45
  puts Ninjs::Notification.added "created #{@module_name}.elements.js"
46
46
  end unless File.exists? "#{@project.root}/elements/#{@module_name}.elements.js"
47
47
 
@@ -50,7 +50,7 @@ module Ninjs
50
50
 
51
51
  def generate_model_file
52
52
  File.open "#{@project.root}/models/#{@module_name}.model.js", "w" do |file|
53
- file << %Q{\t#{@app_name}.#{@module_name}.set_data({\n\t\t\n\t});\n}
53
+ file << %Q{\t#{@project.config.module_alias}.set_data({\n\t\t\n\t});\n}
54
54
  puts Ninjs::Notification.added "created #{@module_name}.model.js"
55
55
  end unless File.exists? "#{@project.root}/models/#{@module_name}.model.js"
56
56
 
@@ -2,11 +2,11 @@ module Ninjs
2
2
  class Notification
3
3
  @@growl_support = false
4
4
  @@indicators = {
5
- :none => "",
6
- :log => "\e[32m>>>\e[0m ",
7
- :event => "\e[33m<<<\e[0m ",
8
- :added => "\e[32m+++\e[0m ",
9
- :error => "\e[0;31m!!!\e[0m "
5
+ none: "",
6
+ log: "\e[32m>>>\e[0m ",
7
+ event: "\e[33m<<<\e[0m ",
8
+ added: "\e[32m+++\e[0m ",
9
+ error: "\e[0;31m!!!\e[0m "
10
10
  }
11
11
 
12
12
  def self.notify(message, style)
data/lib/ninjs/project.rb CHANGED
@@ -3,25 +3,33 @@ module Ninjs
3
3
  attr_reader :root,
4
4
  :config,
5
5
  :modules
6
-
7
-
8
- def initialize(name = nil)
9
- if name.nil?
10
- raise ArgumentError, "Ninjs::Project.new(name): name is required without a configuration file" unless File.exists? 'ninjs.conf'
11
- end
6
+
7
+ def initialize(options = nil)
8
+ settings = {
9
+ name: nil,
10
+ root: Dir.getwd
11
+ }
12
12
 
13
- @root = File.expand_path Dir.getwd
13
+ settings.merge!(options) unless options.nil?
14
+
15
+ @name = settings[:name]
16
+ @root = File.expand_path(settings[:root])
17
+
18
+ if @name.nil?
19
+ raise ArgumentError, "Ninjs::Project.new({ name: 'Name' }): name is required without a configuration file" unless File.exists? "#{@root}/ninjs.conf"
20
+ end
21
+
14
22
  @modules = Array.new
15
23
  @config = Ninjs::Configuration.new @root
16
- @config.setting :name, name unless name.nil?
24
+ @config.name = @name unless @name.nil?
17
25
  end
18
-
26
+
19
27
  def root=(path)
20
28
  @root = File.expand_path path
21
29
  @config.root = @root
22
30
  @config.asset_root = @root
23
31
  end
24
-
32
+
25
33
  def create
26
34
  puts Ninjs::Notification.notice "Creating the #{@config.name} project in #{@root}"
27
35
  create_project_scaffold
@@ -31,7 +39,7 @@ module Ninjs
31
39
  create_ninjs_application_file
32
40
  import_test_files
33
41
  end
34
-
42
+
35
43
  def create_project_scaffold
36
44
  Dir.mkdir "#{@root}" unless File.exists? "#{@root}"
37
45
  Ninjs::Manifest.directories.each do |folder|
@@ -45,7 +53,7 @@ module Ninjs
45
53
  ninjs_lib_secretary = Sprockets::Secretary.new(
46
54
  :root => "#{Ninjs::BASE_DIR}",
47
55
  :load_path => ["repository"],
48
- :source_files => ["repository/ninjs/core/nin.js"]
56
+ source_files: ["repository/ninjs/core/nin.js"]
49
57
  )
50
58
 
51
59
  ninjs_lib_secretary.concatenation.save_to "#{@root}/lib/nin.js"
@@ -55,9 +63,9 @@ module Ninjs
55
63
 
56
64
  def create_utility_lib_file
57
65
  utility_lib_secretary = Sprockets::Secretary.new(
58
- :root => "#{Ninjs::BASE_DIR}",
59
- :load_path => ["repository"],
60
- :source_files => ["repository/ninjs/utilities/all.js"]
66
+ root: "#{Ninjs::BASE_DIR}",
67
+ load_path: ["repository"],
68
+ source_files: ["repository/ninjs/utilities/all.js"]
61
69
  )
62
70
 
63
71
  utility_lib_secretary.concatenation.save_to "#{@root}/lib/utilities.js"
@@ -67,7 +75,7 @@ module Ninjs
67
75
 
68
76
  def create_ninjs_application_file
69
77
  File.open("#{@root}/application/#{@config.name.downcase}.js", "w+") do |file|
70
- file << "//-- Ninjs #{Time.now.to_s} --//\n"
78
+ file << "//-- This file was automatically generated by Ninjs @ #{Time.now.to_s} DO NOT EDIT THIS FILE --//\n"
71
79
  file << File.open("#{@root}/lib/nin.js", 'r').readlines.join('')
72
80
  file << "\nvar #{@config.name} = new NinjsApplication();"
73
81
  end
@@ -104,17 +112,17 @@ module Ninjs
104
112
  @modules = Array.new
105
113
  if @config.src_dir.is_a? Array
106
114
  @config.src_dir.each do |directory|
107
- add_scripts_to_models File.expand_path "#{directory}"
115
+ add_scripts_to_models File.expand_path(directory, @root)
108
116
  end
109
117
  else
110
- add_scripts_to_models File.expand_path "#{@config.src_dir}"
118
+ add_scripts_to_models File.expand_path(@config.src_dir, @root)
111
119
  end
112
120
  end
113
121
 
114
122
  def add_scripts_to_models(directory)
115
123
  Dir["#{directory}/*.js"].each do |file|
116
124
  module_filename = file.gsub(directory, '')
117
- @modules << "#{directory}#{module_filename}" unless module_filename.match(/^_/)
125
+ @modules << "#{directory}#{module_filename}" unless module_filename.match(/^\/_/)
118
126
  end
119
127
  end
120
128
 
@@ -131,7 +139,7 @@ module Ninjs
131
139
  :root => "#{Ninjs::BASE_DIR}",
132
140
  :asset_root => @config.asset_root,
133
141
  :load_path => ["repository"],
134
- :source_files => ["#{module_file}"]
142
+ source_files: ["#{module_file}"]
135
143
  )
136
144
 
137
145
  module_file = ninjs_lib_secretary.concatenation
@@ -185,7 +193,7 @@ module Ninjs
185
193
  :root => "#{Ninjs::BASE_DIR}",
186
194
  :asset_root => @config.asset_root,
187
195
  :load_path => ["repository"],
188
- :source_files => ["#{file}"]
196
+ source_files: ["#{file}"]
189
197
  )
190
198
 
191
199
  application_file = ninjs_lib_secretary.concatenation
@@ -211,7 +219,5 @@ module Ninjs
211
219
  end
212
220
  end
213
221
 
214
- end
215
- # class Project
216
- end
217
- #module Ninjs
222
+ end # class Project
223
+ end # module Ninjs