ninjs 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +86 -25
- data/lib/ninjs.rb +35 -0
- data/lib/ninjs/command.rb +146 -0
- data/lib/ninjs/configuration.rb +84 -0
- data/lib/ninjs/dependencies.rb +16 -0
- data/lib/ninjs/helpers.rb +16 -0
- data/lib/ninjs/manifest.rb +9 -0
- data/lib/ninjs/project.rb +253 -0
- data/ninjs.gemspec +115 -0
- data/repository/jquery/1.1.4.js +2508 -0
- data/repository/jquery/1.2.6.js +32 -0
- data/repository/jquery/1.3.2.js +19 -0
- data/repository/jquery/1.4.2.js +154 -0
- data/repository/jquery/1.4.3.js +166 -0
- data/repository/jquery/1.4.4.js +167 -0
- data/repository/jquery/fancybox/1.3.1.js +1079 -0
- data/repository/jquery/fancybox/assets/1.3.1/css/fancybox.css +363 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/blank.gif +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_close.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_loading.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_nav_left.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_nav_right.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_e.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_n.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_ne.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_nw.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_s.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_se.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_sw.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_w.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_left.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_main.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_over.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_right.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox-x.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox-y.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox.png +0 -0
- data/repository/jquery/fancybox/latest.js +1 -0
- data/repository/jquery/latest.js +1 -0
- data/repository/jquery/mousewheel/3.0.2.js +11 -0
- data/repository/jquery/mousewheel/latest.js +1 -0
- data/repository/json2.js +482 -0
- data/repository/modernizr/1.5.js +28 -0
- data/repository/modernizr/latest.js +1 -0
- data/repository/ninjs/core/existence.js +41 -0
- data/repository/ninjs/core/extend.js +22 -0
- data/repository/ninjs/core/nin.js +138 -0
- data/repository/ninjs/tests/index.html +21 -0
- data/repository/ninjs/tests/ninjs.test.js +109 -0
- data/repository/ninjs/tests/ninjs.utilities.test.js +149 -0
- data/repository/ninjs/utilities/all.js +4 -0
- data/repository/ninjs/utilities/array.js +34 -0
- data/repository/ninjs/utilities/css.js +51 -0
- data/repository/ninjs/utilities/number.js +11 -0
- data/repository/ninjs/utilities/string.js +66 -0
- data/repository/nullconsole.js +7 -0
- data/repository/qunit/assets/css/qunit.css +196 -0
- data/repository/qunit/qunit.js +1374 -0
- data/repository/selectivizr/1.0.js +5 -0
- data/repository/selectivizr/latest.js +1 -0
- data/repository/syntaxhighlighter/default.js +10 -0
- data/repository/syntaxhighlighter/shAutoloader.js +17 -0
- data/repository/syntaxhighlighter/shBrushAS3.js +59 -0
- data/repository/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/repository/syntaxhighlighter/shBrushBash.js +59 -0
- data/repository/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/repository/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/repository/syntaxhighlighter/shBrushCpp.js +97 -0
- data/repository/syntaxhighlighter/shBrushCss.js +91 -0
- data/repository/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/repository/syntaxhighlighter/shBrushDiff.js +41 -0
- data/repository/syntaxhighlighter/shBrushErlang.js +52 -0
- data/repository/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/repository/syntaxhighlighter/shBrushJScript.js +52 -0
- data/repository/syntaxhighlighter/shBrushJava.js +57 -0
- data/repository/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/repository/syntaxhighlighter/shBrushPerl.js +72 -0
- data/repository/syntaxhighlighter/shBrushPhp.js +88 -0
- data/repository/syntaxhighlighter/shBrushPlain.js +33 -0
- data/repository/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/repository/syntaxhighlighter/shBrushPython.js +64 -0
- data/repository/syntaxhighlighter/shBrushRuby.js +55 -0
- data/repository/syntaxhighlighter/shBrushSass.js +94 -0
- data/repository/syntaxhighlighter/shBrushScala.js +51 -0
- data/repository/syntaxhighlighter/shBrushSql.js +66 -0
- data/repository/syntaxhighlighter/shBrushVb.js +56 -0
- data/repository/syntaxhighlighter/shBrushXml.js +69 -0
- data/repository/syntaxhighlighter/shCore.js +17 -0
- data/repository/syntaxhighlighter/shLegacy.js +17 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/test_spec.rb +5 -0
- metadata +100 -3
data/README.textile
CHANGED
@@ -97,7 +97,7 @@ We can see what this module does by simply glancing at the actions method. From
|
|
97
97
|
|
98
98
|
h2. Create module elements
|
99
99
|
|
100
|
-
Another common best practice that Ninjs encourages is cacheing your element selectors. For example, when using jQuery to select a DOM element, it's best practice to assign the result of the selection to a variable
|
100
|
+
Another common best practice that Ninjs encourages is cacheing your element selectors. For example, when using jQuery to select a DOM element, it's best practice to assign the result of the selection to a variable in case you need it again. Here's what it looks like in practice:
|
101
101
|
|
102
102
|
<pre name="code" class="brush: js;">
|
103
103
|
// Bad no-caching
|
@@ -112,7 +112,7 @@ Another common best practice that Ninjs encourages is cacheing your element sele
|
|
112
112
|
|
113
113
|
When we cache our selections, we only have to search the DOM once, improving performance.
|
114
114
|
|
115
|
-
The only problem with this is that we tend to manipulate a lot of selections and our code can become littered with them. At worst, they're strewn about the file
|
115
|
+
The only problem with this is that we tend to manipulate a lot of selections and our code can become littered with them. At worst, they're strewn about the file wherever they are first used, making it easy to accidentally "re-cache" them. At best, all selections are cached in one place and easy to see, which prevents us from accidentally caching them twice. Ninjs goes a step further by putting these cached selectors in their own file in the elements folder.
|
116
116
|
|
117
117
|
Elements belong to a module and can be added using the elements method. To add elements to the hello module, let's add a hello.elements.js file in the elements folder. Next add the elements to the module with the elements method:
|
118
118
|
|
@@ -129,26 +129,7 @@ And that's it for the elements code. We've added a cached element with the id of
|
|
129
129
|
|
130
130
|
//= require '../elements/hello.elements.js'
|
131
131
|
|
132
|
-
|
133
|
-
this.define_properties();
|
134
|
-
this.say_hello();
|
135
|
-
};
|
136
|
-
|
137
|
-
MyApplication.hello.define_properties() = function() {
|
138
|
-
this.greeting = 'Hello';
|
139
|
-
this.name = 'World';
|
140
|
-
}
|
141
|
-
|
142
|
-
MyApplication.hello.say_hello = function() {
|
143
|
-
var message = this.greeting_string();
|
144
|
-
alert(message);
|
145
|
-
};
|
146
|
-
|
147
|
-
MyApplication.hello.greeting_string = function() {
|
148
|
-
return this.greeting + ' ' + this.name + '!';
|
149
|
-
};
|
150
|
-
|
151
|
-
MyApplication.hello.run();
|
132
|
+
...
|
152
133
|
</pre>
|
153
134
|
|
154
135
|
Be sure to require the elements file after the "add_module" method is called. Now all elements defined in the elements method will be available to the module. Let's take our hello example and instead of alerting the greeting, let's put it in the message_box element (assuming an html page with this element):
|
@@ -164,8 +145,88 @@ Be sure to require the elements file after the "add_module" method is called. No
|
|
164
145
|
...
|
165
146
|
</pre>
|
166
147
|
|
167
|
-
Again, this pattern keeps the logic very clear and our code very concise. It's easy to read, test, and refactor. Be careful when naming your cached elements, be sure you're not overwriting another property. With time you'll develop your own naming conventions and standards. The important thing is to focus on good semantic names that accurately describe the properties and behavior of your application.
|
148
|
+
Again, this pattern keeps the logic very clear and our code very concise. It's easy to read, test, and refactor. Be careful when naming your cached elements, be sure you're not overwriting another property of the module. With time you'll develop your own naming conventions and standards. The important thing is to focus on good semantic names that accurately describe the properties and behavior of your application.
|
149
|
+
|
150
|
+
Most modules will be exactly like the one we just created, only with more methods. However, there is one more piece that helps you achieve greater modularity, which is Ninjs models.
|
151
|
+
|
152
|
+
h2. Create a Ninjs model
|
153
|
+
|
154
|
+
Ninjs models are simply files in the models directory that define a data structure. By convention models are simply object literals that are usefull for reusing inside your modules and throughout your application. There is no one way to create or use a model but I'll describe the common use case.
|
168
155
|
|
169
|
-
|
156
|
+
Let's suppose I have multiple "jQueryUI dialog windows":http://jqueryui.com/demos/dialog/ that I want to share a certain default configuration. Instead of creating an options object each time I call dialog on an element, I can use a model. Let's see how this might look in our hello example. Let's create the model in /models/hello.model.js:
|
157
|
+
|
158
|
+
<pre name="code" class="brush: js;">
|
159
|
+
MyApplication.hello.dialog_settings = {
|
160
|
+
width: 300,
|
161
|
+
height: 150,
|
162
|
+
autoOpen: false
|
163
|
+
}
|
164
|
+
</pre>
|
165
|
+
|
166
|
+
Next we include the model in the module:
|
167
|
+
|
168
|
+
<pre name="code" class="brush: js;">
|
169
|
+
MyApplication.add_module('hello');
|
170
|
+
|
171
|
+
//= require '../elements/hello.model.js'
|
172
|
+
//= require '../elements/hello.elements.js'
|
173
|
+
|
174
|
+
...
|
175
|
+
</pre>
|
176
|
+
|
177
|
+
Now whenever I create a dialog in my module, I can use the MyApplication.hello.dialog_settings object:
|
178
|
+
|
179
|
+
<pre name="code" class="brush: js;">
|
180
|
+
// assumes we have elements "error_dialog" and "notice_dialog"
|
181
|
+
// defined in the elements file
|
182
|
+
|
183
|
+
MyApplciation.hello.create_dialogs = function() {
|
184
|
+
this.error_dialog.dialog(this.dialog_settings);
|
185
|
+
this.notice_dialog.dialog(this.dialog_settings);
|
186
|
+
}
|
187
|
+
</pre>
|
188
|
+
|
189
|
+
This way we don't have to keep redefining the same properties each time we call dialog. If we want to modify the defaults, we can use jquery's merge method
|
190
|
+
|
191
|
+
<pre name="code" class="brush: js;">
|
192
|
+
// assumes we have elements "error_dialog" and "notice_dialog"
|
193
|
+
// defined in the elements file
|
194
|
+
|
195
|
+
MyApplciation.hello.create_dialogs = function() {
|
196
|
+
this.error_dialog.dialog(this.dialog_settings);
|
197
|
+
this.notice_dialog.dialog($.extend(MyApplication.hello.dialog_settings, {
|
198
|
+
height: 300,
|
199
|
+
autoOpen: true
|
200
|
+
}));
|
201
|
+
}
|
202
|
+
</pre>
|
203
|
+
|
204
|
+
The model provides a default base that we can build from, helping use to keep our code DRY. There's also an opportunithy here to illustrate the utility of the "ninja" aliases. Notice that inside the dialog function we are unable to use the this.dialog_settings shorthand. This is because this is refering to the dialog and not the module. That's why Ninjs defines the double underscore variable to refer to the current module. The previous example can be rewritten more succinclty like so:
|
205
|
+
|
206
|
+
<pre name="code" class="brush: js;">
|
207
|
+
MyApplciation.hello.create_dialogs = function() {
|
208
|
+
this.error_dialog.dialog(this.dialog_settings);
|
209
|
+
this.notice_dialog.dialog($.extend(__.dialog_settings, {
|
210
|
+
height: 300,
|
211
|
+
autoOpen: true
|
212
|
+
}));
|
213
|
+
}
|
214
|
+
</pre>
|
215
|
+
|
216
|
+
Using "this" in Javascript can be a bit tricky so if your not sure what "this" refers to in any given context, your safe using the "_" (application alias) and "__" (module alias) aliases in Ninjs.
|
217
|
+
|
218
|
+
h1. Compiling our application
|
219
|
+
|
220
|
+
Now that we have a complete module including elements and a model, we need to compile these files into one coherent file to use in our html. To do so we have 2 options. Open a terminal window (command prompt) and navigate to the root of your Ninjs application. We can compile our application with one of 2 commands. The first choice is the compile command. From the root of your Ninjs application type:
|
221
|
+
|
222
|
+
<pre name="code" class="brush: bash;">
|
223
|
+
$ ninjs compile
|
224
|
+
</pre>
|
225
|
+
|
226
|
+
This will compile all the files in the modules folder, resolving all dependencies using the Sprockets engine, and finally outputting them into the application directory with the .module suffix removed. Our hello example module would compile into the application folder as hello.js. Now we can include the hello.js file (along with the myapplication.js) in our html document. Since running compile every time we make a change to any one of our module source files would quickly become a tedious chore, Ninjs also provides a watch command which will watch your root directory for changes and automatically compile when a file is changed. This speeds up development considerably and frankly makes Ninjs usable in a daily development context. To watch a Ninjs project simply navigate to the project root and issue the watch command:
|
227
|
+
|
228
|
+
<pre name="code" class="brush: bash;">
|
229
|
+
$ ninjs watch
|
230
|
+
</pre>
|
170
231
|
|
171
|
-
|
232
|
+
That's the basics of creating a Ninjs application!
|
data/lib/ninjs.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ninjs
|
2
|
+
end
|
3
|
+
|
4
|
+
module Ninjs
|
5
|
+
def version
|
6
|
+
'0.9.4'
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_directory
|
10
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def lib_directory
|
14
|
+
File.expand_path(File.join(File.dirname(__FILE__)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def root_directory
|
18
|
+
Dir.getwd
|
19
|
+
end
|
20
|
+
|
21
|
+
def repository_root
|
22
|
+
base_directory + '/repository/'
|
23
|
+
end
|
24
|
+
|
25
|
+
module_function :version,
|
26
|
+
:base_directory,
|
27
|
+
:lib_directory,
|
28
|
+
:root_directory,
|
29
|
+
:repository_root
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
%w(dependencies configuration helpers manifest project command).each do |lib|
|
34
|
+
require "#{Ninjs.lib_directory}/ninjs/#{lib}"
|
35
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Ninjs
|
2
|
+
module Command
|
3
|
+
def watch
|
4
|
+
require "fssm"
|
5
|
+
project_path = Dir.getwd << '/'
|
6
|
+
raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}ninjs.conf"
|
7
|
+
color_start = "\e[33m"
|
8
|
+
color_end = "\e[0m"
|
9
|
+
puts "\e[32m>>>#{color_end} Ninjs are watching for changes. Press Ctrl-C to stop."
|
10
|
+
project = Ninjs::Project.init_with_config(project_path)
|
11
|
+
project.update
|
12
|
+
|
13
|
+
FSSM.monitor do
|
14
|
+
path "#{project_path}elements" do
|
15
|
+
glob "**/*.js"
|
16
|
+
|
17
|
+
update do |base, relative|
|
18
|
+
puts "#{color_start}<<<#{color_end} change detected in #{relative}"
|
19
|
+
project.update
|
20
|
+
end
|
21
|
+
|
22
|
+
create do |base, relative|
|
23
|
+
puts "#{relative} created"
|
24
|
+
project.update
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
path "#{project_path}models" do
|
29
|
+
glob "**/*.js"
|
30
|
+
|
31
|
+
update do |base, relative|
|
32
|
+
puts "#{@color_start}<<<#{@color_end} change detected in #{relative}"
|
33
|
+
project.update
|
34
|
+
end
|
35
|
+
|
36
|
+
create do |base, relative|
|
37
|
+
puts "#{relative} created"
|
38
|
+
project.update
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
path "#{project_path}modules" do
|
43
|
+
glob "**/*.js"
|
44
|
+
|
45
|
+
update do |base, relative|
|
46
|
+
puts "#{color_start}<<<#{color_end} change detected in #{relative}"
|
47
|
+
project.update
|
48
|
+
end
|
49
|
+
|
50
|
+
create do |base, relative|
|
51
|
+
puts "#{relative} created"
|
52
|
+
project.update
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
path "#{project_path}lib" do
|
57
|
+
glob "**/*.js"
|
58
|
+
|
59
|
+
update do |base, relative|
|
60
|
+
puts "#{color_start}<<<#{color_end} change detected in #{relative}"
|
61
|
+
project.config.read
|
62
|
+
project.update_application_file
|
63
|
+
project.update
|
64
|
+
end
|
65
|
+
|
66
|
+
create do |base, relative|
|
67
|
+
puts "+++ created #{relative}"
|
68
|
+
project.update
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
path "#{project_path}plugins" do
|
73
|
+
glob "**/*.js"
|
74
|
+
|
75
|
+
update do |base, relative|
|
76
|
+
puts "#{color_start}<<<#{color_end} change detected in #{relative}"
|
77
|
+
project.config.read
|
78
|
+
project.update_application_file
|
79
|
+
project.update
|
80
|
+
end
|
81
|
+
|
82
|
+
create do |base, relative|
|
83
|
+
puts "+++ created #{relative}"
|
84
|
+
project.update
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
path "#{project_path}" do
|
89
|
+
glob "**/*.conf"
|
90
|
+
|
91
|
+
update do |base, relative|
|
92
|
+
puts "#{color_start}<<<#{color_end} change detected in #{relative}"
|
93
|
+
project.config.read
|
94
|
+
project.update_application_file
|
95
|
+
project.update
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def create(name, directory = false)
|
104
|
+
raise 'you must specify a project name: ninjs create ProjectName' if name.nil?
|
105
|
+
project = directory ? Ninjs::Project.new(name, directory) : Ninjs::Project.new(name)
|
106
|
+
project.create
|
107
|
+
end
|
108
|
+
|
109
|
+
def compile
|
110
|
+
project_path = Dir.getwd << '/'
|
111
|
+
raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
|
112
|
+
project = Ninjs::Project.init_with_config(project_path)
|
113
|
+
project.update
|
114
|
+
end
|
115
|
+
|
116
|
+
def import(package)
|
117
|
+
Ninjs::PackageManager.import(package)
|
118
|
+
end
|
119
|
+
|
120
|
+
def help
|
121
|
+
puts <<-DOC
|
122
|
+
|
123
|
+
Description:
|
124
|
+
The ninjs command line tool will compile your ninjs application into modules.
|
125
|
+
To compile your ninjs application into module files:
|
126
|
+
|
127
|
+
Usage: ninjs [action] [options]
|
128
|
+
|
129
|
+
Actions:
|
130
|
+
compile Compiles the ninjs project in the current working directory
|
131
|
+
watch Watches the current working directory for
|
132
|
+
file changes and compiles when files change
|
133
|
+
create Generates ninjs application architecture and files
|
134
|
+
Options:
|
135
|
+
-p, --directory Optional install directory for a new ninjs project
|
136
|
+
(creates the folder if it does not exist)
|
137
|
+
|
138
|
+
Example:
|
139
|
+
ninjs create MyApplication
|
140
|
+
ninjs watch
|
141
|
+
DOC
|
142
|
+
end
|
143
|
+
|
144
|
+
module_function :create, :watch, :compile, :help, :import
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Ninjs
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_reader :name,
|
5
|
+
:project_path,
|
6
|
+
:app_filename,
|
7
|
+
:directory,
|
8
|
+
:output,
|
9
|
+
:dependencies,
|
10
|
+
:autoload,
|
11
|
+
:config_path,
|
12
|
+
:asset_root
|
13
|
+
|
14
|
+
def initialize(project_path, name = 'NinjsApplication')
|
15
|
+
@defaults = {
|
16
|
+
:name => name,
|
17
|
+
:project_path => project_path,
|
18
|
+
:asset_root => project_path,
|
19
|
+
:output => 'expanded',
|
20
|
+
:dependencies => ['<jquery/latest>'],
|
21
|
+
:autoload => ['<ninjs/utilities/all>']
|
22
|
+
}
|
23
|
+
|
24
|
+
@defaults.each do |label, setting|
|
25
|
+
instance_variable_set("@#{label}", setting)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
default_content = conf_content @defaults
|
31
|
+
create_conf_file default_content
|
32
|
+
end
|
33
|
+
|
34
|
+
def conf_content(options)
|
35
|
+
content = <<-CONF
|
36
|
+
name: #{options[:name]}
|
37
|
+
project_path: #{options[:project_path]}
|
38
|
+
asset_root: #{options[:project_path]}
|
39
|
+
output: #{options[:output]}
|
40
|
+
dependencies: [#{options[:dependencies].join(', ')}]
|
41
|
+
autoload: [#{options[:autoload].join(', ')}]
|
42
|
+
CONF
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_conf_file(content)
|
46
|
+
File.open("#{@project_path}ninjs.conf", "w+") do |conf_file|
|
47
|
+
conf_file << conf_content(@defaults)
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "ninjs.conf created"
|
51
|
+
end
|
52
|
+
|
53
|
+
def update
|
54
|
+
content = conf_content({
|
55
|
+
:name => @name,
|
56
|
+
:project_path => @project_path,
|
57
|
+
:asset_root => @project_path,
|
58
|
+
:output => @output,
|
59
|
+
:dependencies => @dependencies,
|
60
|
+
:autoload => @autoload
|
61
|
+
})
|
62
|
+
create_conf_file content
|
63
|
+
end
|
64
|
+
|
65
|
+
def read
|
66
|
+
begin
|
67
|
+
raise IOError, "#{@project_path}ninjs.conf does not exist", caller unless File.exists? "#{@project_path}ninjs.conf"
|
68
|
+
config = YAML.load_file("#{@project_path}ninjs.conf")
|
69
|
+
|
70
|
+
@project_path = config['project_path']
|
71
|
+
@asset_root = config['asset_root']
|
72
|
+
@name = config['name']
|
73
|
+
@app_filename = config['name'].downcase
|
74
|
+
@output = config['output']
|
75
|
+
@dependencies = config['dependencies'] || Array.new
|
76
|
+
@autoload = config['autoload'] || Array.new
|
77
|
+
rescue IOError => e
|
78
|
+
puts e.message
|
79
|
+
puts e.backtrace.inspect
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'yaml'
|
3
|
+
require 'jsmin'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'sprockets'
|
6
|
+
require 'ftools'
|
7
|
+
require 'time'
|
8
|
+
rescue LoadError
|
9
|
+
require 'rubygems'
|
10
|
+
require 'yaml'
|
11
|
+
require 'jsmin'
|
12
|
+
require 'tempfile'
|
13
|
+
require 'sprockets'
|
14
|
+
require 'ftools'
|
15
|
+
require 'time'
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ninjs
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
def create_module_filename(module_name)
|
5
|
+
split = module_name.split(/[\.\-\s]/)
|
6
|
+
module_filename = String.new
|
7
|
+
split.each do |piece|
|
8
|
+
module_filename << piece unless piece.match(/^module$|^js$/i)
|
9
|
+
end
|
10
|
+
module_filename
|
11
|
+
end
|
12
|
+
|
13
|
+
module_function :create_module_filename
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|