ninjs 0.14.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -2
- data/.travis.yml +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -11
- data/README.md +108 -93
- data/Rakefile +17 -7
- data/VERSION +1 -1
- data/bin/ninjs +24 -22
- data/lib/ninjs/command.rb +32 -21
- data/lib/ninjs/configuration.rb +35 -53
- data/lib/ninjs/generator.rb +6 -6
- data/lib/ninjs/notification.rb +5 -5
- data/lib/ninjs/project.rb +31 -25
- data/ninjs.gemspec +18 -142
- data/repository/ninjs/core/application.js +13 -24
- data/repository/ninjs/core/dom.js +87 -68
- data/repository/ninjs/core/existence.js +44 -105
- data/repository/ninjs/core/extend.js +11 -32
- data/repository/ninjs/core/module.js +53 -107
- data/repository/ninjs/core/nin.js +5 -7
- data/repository/ninjs/tests/extension.test.js +0 -10
- data/repository/ninjs/tests/index.html +19 -20
- data/repository/ninjs/tests/module.test.js +52 -56
- data/repository/ninjs/utilities/array.js +8 -8
- data/repository/ninjs/utilities/cookie.js +59 -0
- data/repository/ninjs/utilities/css.js +7 -7
- data/repository/ninjs/utilities/number.js +2 -2
- data/repository/ninjs/utilities/string.js +26 -26
- data/spec/cli_spec.rb +90 -88
- data/spec/command_spec.rb +104 -137
- data/spec/configuration_spec.rb +23 -37
- data/spec/fixtures/_global.module.js +9 -0
- data/spec/fixtures/compressed.myapp.js +23 -44
- data/spec/fixtures/foo.elements.js +1 -1
- data/spec/fixtures/foo.js +5 -5
- data/spec/fixtures/foo.model.js +1 -1
- data/spec/fixtures/foo.module.js +3 -3
- data/spec/fixtures/hello.elements.js +1 -1
- data/spec/fixtures/hello.js +5 -5
- data/spec/fixtures/hello.model.js +1 -1
- data/spec/fixtures/hello.module.js +3 -3
- data/spec/fixtures/myapp.initial.js +198 -329
- data/spec/fixtures/myapp.js +285 -357
- data/spec/fixtures/mymodule.alias.module.js +2 -2
- data/spec/fixtures/mymodule.dependencies.module.js +2 -2
- data/spec/fixtures/mymodule.elements.js +1 -1
- data/spec/fixtures/mymodule.model.js +1 -1
- data/spec/fixtures/mymodule.module.js +2 -2
- data/spec/fixtures/mymodule.module_alias.module.js +10 -0
- data/spec/fixtures/new.ninjs.conf +2 -0
- data/spec/fixtures/nin.js +198 -329
- data/spec/fixtures/ninjs.conf +2 -0
- data/spec/fixtures/updated.ninjs.conf +8 -0
- data/spec/generator_spec.rb +37 -26
- data/spec/ninjs_spec.rb +6 -6
- data/spec/project_spec.rb +229 -221
- data/spec/spec_helper.rb +3 -1
- data/spec/testspec_spec.rb +7 -0
- metadata +28 -145
- data/repository/json2.js +0 -482
- data/repository/modernizr/1.5.js +0 -28
- data/repository/modernizr/latest.js +0 -1
- data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
- data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
- data/repository/ninjs/docs/Data/FileInfo.nd +0 -16
- data/repository/ninjs/docs/Data/ImageFileInfo.nd +0 -0
- data/repository/ninjs/docs/Data/ImageReferenceTable.nd +0 -0
- data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
- data/repository/ninjs/docs/Data/PreviousMenuState.nd +0 -0
- data/repository/ninjs/docs/Data/PreviousSettings.nd +0 -0
- data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
- data/repository/ninjs/docs/Languages.txt +0 -113
- data/repository/ninjs/docs/Menu.txt +0 -63
- data/repository/ninjs/docs/Topics.txt +0 -81
- data/repository/ninjs/docs/files/core/application-js.html +0 -44
- data/repository/ninjs/docs/files/core/existence-js.html +0 -60
- data/repository/ninjs/docs/files/core/extend-js.html +0 -55
- data/repository/ninjs/docs/files/core/module-js.html +0 -80
- data/repository/ninjs/docs/files/core/nin-js.html +0 -38
- data/repository/ninjs/docs/index.html +0 -1
- data/repository/ninjs/docs/index/Classes.html +0 -33
- data/repository/ninjs/docs/index/Files.html +0 -45
- data/repository/ninjs/docs/index/Functions.html +0 -65
- data/repository/ninjs/docs/index/General.html +0 -85
- data/repository/ninjs/docs/index/Variables.html +0 -45
- data/repository/ninjs/docs/javascript/main.js +0 -841
- data/repository/ninjs/docs/javascript/prettify.js +0 -1526
- data/repository/ninjs/docs/javascript/searchdata.js +0 -152
- data/repository/ninjs/docs/search/ClassesN.html +0 -20
- data/repository/ninjs/docs/search/FilesA.html +0 -20
- data/repository/ninjs/docs/search/FilesE.html +0 -20
- data/repository/ninjs/docs/search/FilesM.html +0 -20
- data/repository/ninjs/docs/search/FilesN.html +0 -20
- data/repository/ninjs/docs/search/FunctionsA.html +0 -20
- data/repository/ninjs/docs/search/FunctionsC.html +0 -20
- data/repository/ninjs/docs/search/FunctionsE.html +0 -20
- data/repository/ninjs/docs/search/FunctionsI.html +0 -20
- data/repository/ninjs/docs/search/FunctionsM.html +0 -20
- data/repository/ninjs/docs/search/FunctionsR.html +0 -20
- data/repository/ninjs/docs/search/FunctionsS.html +0 -20
- data/repository/ninjs/docs/search/FunctionsSymbols.html +0 -20
- data/repository/ninjs/docs/search/FunctionsU.html +0 -20
- data/repository/ninjs/docs/search/GeneralA.html +0 -20
- data/repository/ninjs/docs/search/GeneralC.html +0 -20
- data/repository/ninjs/docs/search/GeneralD.html +0 -20
- data/repository/ninjs/docs/search/GeneralE.html +0 -20
- data/repository/ninjs/docs/search/GeneralF.html +0 -20
- data/repository/ninjs/docs/search/GeneralI.html +0 -20
- data/repository/ninjs/docs/search/GeneralM.html +0 -20
- data/repository/ninjs/docs/search/GeneralN.html +0 -20
- data/repository/ninjs/docs/search/GeneralR.html +0 -20
- data/repository/ninjs/docs/search/GeneralS.html +0 -20
- data/repository/ninjs/docs/search/GeneralSymbols.html +0 -20
- data/repository/ninjs/docs/search/GeneralT.html +0 -20
- data/repository/ninjs/docs/search/GeneralU.html +0 -20
- data/repository/ninjs/docs/search/GeneralV.html +0 -20
- data/repository/ninjs/docs/search/NoResults.html +0 -15
- data/repository/ninjs/docs/search/VariablesD.html +0 -20
- data/repository/ninjs/docs/search/VariablesN.html +0 -20
- data/repository/ninjs/docs/search/VariablesR.html +0 -20
- data/repository/ninjs/docs/search/VariablesT.html +0 -20
- data/repository/ninjs/docs/styles/main.css +0 -828
- data/repository/nullconsole.js +0 -7
- data/repository/qunit/assets/css/qunit.css +0 -196
- data/repository/qunit/qunit.js +0 -1374
- data/repository/selectivizr/1.0.js +0 -5
- data/repository/selectivizr/latest.js +0 -1
- data/repository/syntaxhighlighter/all.js +0 -11
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCore.css +0 -226
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDefault.css +0 -328
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDjango.css +0 -331
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEclipse.css +0 -339
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEmacs.css +0 -324
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMDUltra.css +0 -324
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMidnight.css +0 -324
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreRDark.css +0 -324
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDefault.css +0 -117
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDjango.css +0 -120
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEclipse.css +0 -128
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEmacs.css +0 -113
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMDUltra.css +0 -113
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMidnight.css +0 -113
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeRDark.css +0 -113
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCore.scss +0 -216
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDefault.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDjango.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEclipse.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEmacs.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreFadeToGrey.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMDUltra.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMidnight.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreRDark.scss +0 -2
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDefault.scss +0 -7
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDjango.scss +0 -36
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEclipse.scss +0 -48
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEmacs.scss +0 -32
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeFadeToGrey.scss +0 -36
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMDUltra.scss +0 -32
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMidnight.scss +0 -32
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeRDark.scss +0 -32
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_theme_template.scss +0 -120
- data/repository/syntaxhighlighter/shAutoloader.js +0 -17
- data/repository/syntaxhighlighter/shBrushAS3.js +0 -59
- data/repository/syntaxhighlighter/shBrushAppleScript.js +0 -75
- data/repository/syntaxhighlighter/shBrushBash.js +0 -59
- data/repository/syntaxhighlighter/shBrushCSharp.js +0 -65
- data/repository/syntaxhighlighter/shBrushColdFusion.js +0 -100
- data/repository/syntaxhighlighter/shBrushCpp.js +0 -97
- data/repository/syntaxhighlighter/shBrushCss.js +0 -91
- data/repository/syntaxhighlighter/shBrushDelphi.js +0 -55
- data/repository/syntaxhighlighter/shBrushDiff.js +0 -41
- data/repository/syntaxhighlighter/shBrushErlang.js +0 -52
- data/repository/syntaxhighlighter/shBrushGroovy.js +0 -67
- data/repository/syntaxhighlighter/shBrushJScript.js +0 -52
- data/repository/syntaxhighlighter/shBrushJava.js +0 -57
- data/repository/syntaxhighlighter/shBrushJavaFX.js +0 -58
- data/repository/syntaxhighlighter/shBrushPerl.js +0 -72
- data/repository/syntaxhighlighter/shBrushPhp.js +0 -88
- data/repository/syntaxhighlighter/shBrushPlain.js +0 -33
- data/repository/syntaxhighlighter/shBrushPowerShell.js +0 -74
- data/repository/syntaxhighlighter/shBrushPython.js +0 -64
- data/repository/syntaxhighlighter/shBrushRuby.js +0 -55
- data/repository/syntaxhighlighter/shBrushSass.js +0 -94
- data/repository/syntaxhighlighter/shBrushScala.js +0 -51
- data/repository/syntaxhighlighter/shBrushSql.js +0 -66
- data/repository/syntaxhighlighter/shBrushVb.js +0 -56
- data/repository/syntaxhighlighter/shBrushXml.js +0 -69
- data/repository/syntaxhighlighter/shCore.js +0 -17
- 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
|
-
|
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.
|
1
|
+
0.16.0
|
data/bin/ninjs
CHANGED
@@ -72,22 +72,22 @@ footer = <<-FOOTER
|
|
72
72
|
FOOTER
|
73
73
|
|
74
74
|
help = {
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
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
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
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
|
-
|
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
|
-
:
|
170
|
-
:
|
171
|
+
model: options[:model],
|
172
|
+
elements: options[:elements]
|
171
173
|
}
|
172
174
|
|
173
175
|
Ninjs::Command.generate({
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
177
|
-
:
|
178
|
-
:
|
179
|
-
:
|
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
|
-
|
7
|
-
raise "ninjs.conf was not located in #{
|
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["#{
|
17
|
+
watch_hash["#{path}/#{dir}"] = "**/*.js"
|
18
18
|
end
|
19
19
|
|
20
|
-
watch_hash[
|
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
|
-
|
48
|
+
def create(config = nil)
|
49
|
+
settings = {
|
50
|
+
name: nil,
|
51
|
+
root: File.expand_path(Dir.getwd)
|
52
|
+
}
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
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(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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 = "#{
|
68
|
-
raise "ninjs.conf was not located in #{conf_path}" unless File.exists?
|
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
|
-
|
76
|
-
raise "ninjs.conf was not located in #{
|
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
|
data/lib/ninjs/configuration.rb
CHANGED
@@ -1,82 +1,64 @@
|
|
1
1
|
module Ninjs
|
2
2
|
class Configuration
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:
|
14
|
-
|
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
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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("#{@
|
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
|
data/lib/ninjs/generator.rb
CHANGED
@@ -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] || { :
|
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
|
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#{@
|
30
|
-
module_content << "\t#{@
|
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{\
|
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#{@
|
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
|
|
data/lib/ninjs/notification.rb
CHANGED
@@ -2,11 +2,11 @@ module Ninjs
|
|
2
2
|
class Notification
|
3
3
|
@@growl_support = false
|
4
4
|
@@indicators = {
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
|
7
|
+
def initialize(options = nil)
|
8
|
+
settings = {
|
9
|
+
name: nil,
|
10
|
+
root: Dir.getwd
|
11
|
+
}
|
12
12
|
|
13
|
-
|
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.
|
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
|
-
:
|
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
|
-
:
|
59
|
-
:
|
60
|
-
:
|
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}
|
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
|
115
|
+
add_scripts_to_models File.expand_path(directory, @root)
|
108
116
|
end
|
109
117
|
else
|
110
|
-
add_scripts_to_models File.expand_path
|
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
|
-
:
|
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
|
-
:
|
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
|
-
|
216
|
-
end
|
217
|
-
#module Ninjs
|
222
|
+
end # class Project
|
223
|
+
end # module Ninjs
|