judojs 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.markdown +29 -0
- data/bin/jpm +52 -0
- data/bin/judojs +52 -0
- data/lib/judojs/command.rb +136 -0
- data/lib/judojs/configuration.rb +77 -0
- data/lib/judojs/dependencies.rb +14 -0
- data/lib/judojs/helpers.rb +16 -0
- data/lib/judojs/jpm.rb +62 -0
- data/lib/judojs/project.rb +193 -0
- data/lib/judojs.rb +31 -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/latest.js +1 -0
- data/repository/judojs/core/existence.js +41 -0
- data/repository/judojs/core/extend.js +22 -0
- data/repository/judojs/core/judo.js +26 -0
- data/repository/judojs/tests/index.html +21 -0
- data/repository/judojs/tests/judojs.test.js +109 -0
- data/repository/judojs/tests/judojs.utilities.test.js +149 -0
- data/repository/judojs/utilities/all.js +2 -0
- data/repository/judojs/utilities/array.js +34 -0
- data/repository/judojs/utilities/string.js +66 -0
- data/repository/modernizr/1.5.js +28 -0
- data/repository/modernizr/latest.js +1 -0
- data/repository/selectivizr/1.0.js +5 -0
- data/repository/selectivizr/latest.js +1 -0
- data/tests/fixtures/global.js +6 -0
- data/tests/fixtures/global.module.js +3 -0
- data/tests/fixtures/judojs.conf +5 -0
- data/tests/fixtures/myapplication.js +90 -0
- data/tests/fixtures/test.elements.js +4 -0
- data/tests/fixtures/test.js +2 -0
- data/tests/fixtures/test.model.js +3 -0
- data/tests/fixtures/test.module.js +12 -0
- data/tests/fixtures/update.judojs.conf +4 -0
- data/tests/fixtures/updated.myapplication.js +27 -0
- data/tests/fixtures/utilities.js +100 -0
- data/tests/jpm_test.rb +10 -0
- data/tests/judo_test.rb +12 -0
- data/tests/project_test.rb +91 -0
- data/tests/update_test.rb +70 -0
- metadata +165 -0
data/LICENSE.markdown
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Copyright (c) 2010 Dayton D. Nolan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
No attribution is required by products that make use of this software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
Except as contained in this notice, the name(s) of the above copyright
|
24
|
+
holders shall not be used in advertising or otherwise to promote the sale,
|
25
|
+
use or other dealings in this Software without prior written authorization.
|
26
|
+
|
27
|
+
Contributors to this project agree to grant all rights to the copyright
|
28
|
+
holder of the primary product. Attribution is maintained in the source
|
29
|
+
control history of the product.
|
data/bin/jpm
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "simpleconsole"
|
7
|
+
require "fileutils"
|
8
|
+
require "#{root}/judojs.rb"
|
9
|
+
rescue LoadError
|
10
|
+
require "rubygems"
|
11
|
+
require "simpleconsole"
|
12
|
+
require "fileutils"
|
13
|
+
require "#{root}/judojs.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
class Controller < SimpleConsole::Controller
|
17
|
+
params :bool => {:h => :help}
|
18
|
+
|
19
|
+
def default
|
20
|
+
Judojs::PackageManager.help
|
21
|
+
end
|
22
|
+
|
23
|
+
def install
|
24
|
+
packages = ARGV.uniq!.reject{ |a| a.match(/^install$/) }
|
25
|
+
Judojs::PackageManager.install(packages)
|
26
|
+
end
|
27
|
+
|
28
|
+
def import
|
29
|
+
package = ARGV[1]
|
30
|
+
Judojs::PackageManager.import(package)
|
31
|
+
end
|
32
|
+
|
33
|
+
def uninstall
|
34
|
+
packages = ARGV.uniq!.reject{ |a| a.match(/^uninstall$/) }
|
35
|
+
puts "Are you sure you wish to uninstall the following packages (y/n)? : \e[31m" + packages.join(", ") + "\e[0m"
|
36
|
+
confirm = STDIN.gets.chomp
|
37
|
+
confirmed_uninstall = confirm.match(/^y/i) ? true : false
|
38
|
+
Judojs::PackageManager.uninstall(packages) if confirmed_uninstall
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class View < SimpleConsole::View
|
43
|
+
def default
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def import
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
SimpleConsole::Application.run(ARGV, Controller, View)
|
data/bin/judojs
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "simpleconsole"
|
7
|
+
require "fssm"
|
8
|
+
require "#{root}/judojs.rb"
|
9
|
+
rescue LoadError
|
10
|
+
require "rubygems"
|
11
|
+
require "simpleconsole"
|
12
|
+
require "fssm"
|
13
|
+
require "#{root}/judojs.rb"
|
14
|
+
end
|
15
|
+
# TODO get rid of the SimpleConsole dependency
|
16
|
+
class Controller < SimpleConsole::Controller
|
17
|
+
params :string => {:n => :name,
|
18
|
+
:d => :directory},
|
19
|
+
:bool => {:h => :help}
|
20
|
+
|
21
|
+
def default
|
22
|
+
Judojs::Command.help
|
23
|
+
end
|
24
|
+
|
25
|
+
def help
|
26
|
+
Judojs::Command.help
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
name = params[:name]
|
31
|
+
directory = params[:directory] || '/'
|
32
|
+
raise 'name is undefined: judojs create -n "MyAppName"' if name.nil?
|
33
|
+
Judojs::Command.create(name, directory)
|
34
|
+
end
|
35
|
+
|
36
|
+
def compile
|
37
|
+
Judojs::Command.compile
|
38
|
+
end
|
39
|
+
|
40
|
+
def watch
|
41
|
+
Judojs::Command.watch
|
42
|
+
end
|
43
|
+
|
44
|
+
def import
|
45
|
+
Judojs::Command.import
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class View < SimpleConsole::View
|
50
|
+
end
|
51
|
+
|
52
|
+
SimpleConsole::Application.run(ARGV, Controller, View)
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module Judojs
|
2
|
+
module Command
|
3
|
+
def watch
|
4
|
+
require "fssm"
|
5
|
+
project_path = Dir.getwd << '/'
|
6
|
+
raise "judojs.conf was not located in #{project_path}" unless File.exists? "#{project_path}judojs.conf"
|
7
|
+
color_start = "\e[33m"
|
8
|
+
color_end = "\e[0m"
|
9
|
+
puts "\e[32m>>>#{color_end} Judojs is watching for changes. Press Ctrl-C to stop."
|
10
|
+
project = Judojs::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}" do
|
73
|
+
glob "**/*.conf"
|
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
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def create(name, directory = false)
|
88
|
+
raise 'you must specify a project name: judojs create -n "ProjectName"' if name.nil?
|
89
|
+
project = directory ? Judojs::Project.new(name, directory) : Judojs::Project.new(name)
|
90
|
+
project.create
|
91
|
+
end
|
92
|
+
|
93
|
+
def compile
|
94
|
+
project_path = Dir.getwd << '/'
|
95
|
+
raise "judojs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/judojs.conf"
|
96
|
+
project = Judojs::Project.init_with_config(project_path)
|
97
|
+
project.update
|
98
|
+
end
|
99
|
+
|
100
|
+
def import(package)
|
101
|
+
Judojs::PackageManager.import(package)
|
102
|
+
end
|
103
|
+
|
104
|
+
def help
|
105
|
+
puts <<-DOC
|
106
|
+
|
107
|
+
Description:
|
108
|
+
The judojs command line tool will compile your judojs application into modules.
|
109
|
+
To compile your judojs application into module files:
|
110
|
+
|
111
|
+
Usage: judojs [action] [options]
|
112
|
+
|
113
|
+
Actions:
|
114
|
+
compile Compiles the judojs project in the current working directory
|
115
|
+
watch Watches the current working directory for
|
116
|
+
file changes and compiles when files change
|
117
|
+
create Generates judojs application architecture and files
|
118
|
+
|
119
|
+
Options:
|
120
|
+
-n, --name Name of the judojs application to create
|
121
|
+
-d, --directory Optional install directory for a new judojs project
|
122
|
+
(creates the folder if it does not exist)
|
123
|
+
|
124
|
+
Example:
|
125
|
+
// Generate a new judojs application in the js folder
|
126
|
+
// (creates folder if it doesn't exist)
|
127
|
+
judojs create -n "MyApplication" -d "js"
|
128
|
+
|
129
|
+
// cd to the judojs root folder (ie. js)
|
130
|
+
judojs watch -or- judojs compile
|
131
|
+
DOC
|
132
|
+
end
|
133
|
+
|
134
|
+
module_function :create, :watch, :compile, :help, :import
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Judojs
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_reader :project_path,
|
5
|
+
:name,
|
6
|
+
:app_filename,
|
7
|
+
:directory,
|
8
|
+
:output,
|
9
|
+
:autoload,
|
10
|
+
:config_path,
|
11
|
+
:asset_root
|
12
|
+
|
13
|
+
def initialize(project_path, name = 'JudoApplication')
|
14
|
+
@project_path = project_path
|
15
|
+
@asset_root = project_path
|
16
|
+
@name = name
|
17
|
+
@output = 'expanded'
|
18
|
+
@autoload = Array.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
conf_exists = File.exists? "#{@project_path}judojs.conf"
|
23
|
+
|
24
|
+
if conf_exists
|
25
|
+
autoload = @autoload.empty? ? 'autoload: []' : 'autoload: ["' << @autoload.join('", "') << '"]'
|
26
|
+
else
|
27
|
+
autoload = @autoload.empty? ? '#autoload: ["<judojs/utilities/all>", "../plugins/local_lib_file"]' : @autoload.join('", "')
|
28
|
+
end
|
29
|
+
|
30
|
+
conf_content = <<-CONF
|
31
|
+
project_path: #{@project_path}
|
32
|
+
asset_root: #{@project_path}
|
33
|
+
name: #{@name}
|
34
|
+
output: #{@output}
|
35
|
+
#{autoload}
|
36
|
+
CONF
|
37
|
+
|
38
|
+
File.open("#{@project_path}judojs.conf", "w+") do |conf_file|
|
39
|
+
conf_file << conf_content
|
40
|
+
end
|
41
|
+
|
42
|
+
message = conf_exists ? "judojs.conf updated" : "judojs.conf created"
|
43
|
+
puts message
|
44
|
+
end
|
45
|
+
|
46
|
+
def read
|
47
|
+
begin
|
48
|
+
raise IOError, "#{@project_path}judojs.conf does not exist", caller unless File.exists? "#{@project_path}judojs.conf"
|
49
|
+
config_yaml = File.open("#{@project_path}judojs.conf", "r").readlines.join('')
|
50
|
+
config = YAML::load config_yaml
|
51
|
+
|
52
|
+
@project_path = config['project_path']
|
53
|
+
@asset_root = config['asset_root']
|
54
|
+
@name = config['name']
|
55
|
+
@app_filename = config['name'].downcase
|
56
|
+
@output = config['output']
|
57
|
+
@autoload = config['autoload'] || Array.new
|
58
|
+
rescue RuntimeError => e
|
59
|
+
puts e.message
|
60
|
+
puts e.backtrace.inspect
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def update
|
65
|
+
create
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_config(config)
|
69
|
+
@name = config[:name] unless config[:name].nil?
|
70
|
+
@app_filename = config[:app_filename] unless config[:app_filename].nil?
|
71
|
+
@directory = '/'
|
72
|
+
@output = config[:output] unless config[:output].nil?
|
73
|
+
@autoload = config[:autoload] || nil
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Judojs
|
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
|
data/lib/judojs/jpm.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Judojs
|
2
|
+
module PackageManager
|
3
|
+
|
4
|
+
def import(package)
|
5
|
+
dir = Dir.getwd
|
6
|
+
package_path = dir + '/' + package
|
7
|
+
full_package_path = Judojs.repository_root + package
|
8
|
+
|
9
|
+
raise "#{package_path} is not a directory" unless File.directory? "#{package_path}"
|
10
|
+
raise "#{package_path} does not exist" unless File.exists? "#{package_path}"
|
11
|
+
raise "#{Judojs.repository_root}#{package} already exists" if File.exists? "#{Judojs.repository_root}#{package}"
|
12
|
+
|
13
|
+
Dir.mkdir(full_package_path) unless File.exists?(full_package_path)
|
14
|
+
FileUtils.cp_r(package_path, Judojs.repository_root)
|
15
|
+
end
|
16
|
+
|
17
|
+
def install(packages)
|
18
|
+
packages.each do |package|
|
19
|
+
import package
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def uninstall(packages)
|
24
|
+
packages.each do |package|
|
25
|
+
package_path = Judojs.repository_root + package
|
26
|
+
raise "no program named #{package} installed" unless File.directory? "#{package_path}"
|
27
|
+
|
28
|
+
FileUtils.rm_r package_path
|
29
|
+
raise "Could not delete package. Try checking the file permissions in #{package_path}" if File.exists? package_path
|
30
|
+
puts "#{package} uninstalled successfully" unless File.exists? package_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def list
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def help
|
43
|
+
puts <<-DOC
|
44
|
+
|
45
|
+
Description:
|
46
|
+
The jpm package managers enables you to manage the judojs packages installed on your system:
|
47
|
+
|
48
|
+
Usage: jpm [action]
|
49
|
+
|
50
|
+
Actions:
|
51
|
+
install Install a package
|
52
|
+
|
53
|
+
Example:
|
54
|
+
// Install the fancybox plugin from the judojs repository
|
55
|
+
jpm install fancybox
|
56
|
+
DOC
|
57
|
+
end
|
58
|
+
|
59
|
+
module_function :install, :import, :uninstall, :help
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
module Judojs
|
2
|
+
class Project
|
3
|
+
|
4
|
+
def self.init_with_config(project_path)
|
5
|
+
config = Judojs::Configuration.new project_path
|
6
|
+
config.read
|
7
|
+
|
8
|
+
project = Project.new
|
9
|
+
project.config = config
|
10
|
+
project.project_path = config.project_path
|
11
|
+
project.app_filename = config.name.downcase
|
12
|
+
project
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :app_filename,
|
16
|
+
:project_path,
|
17
|
+
:config,
|
18
|
+
:manifest
|
19
|
+
attr_writer :config,
|
20
|
+
:project_path,
|
21
|
+
:app_filename
|
22
|
+
|
23
|
+
def initialize(name = 'JudoApplication', project_dir = '/')
|
24
|
+
name.gsub!(/\s|\-|\./)
|
25
|
+
proj_dir = project_dir || '/'
|
26
|
+
proj_dir += '/' unless proj_dir.match(/\/$/)
|
27
|
+
proj_dir = '/' << proj_dir unless proj_dir.match(/^\//)
|
28
|
+
|
29
|
+
@color_start = "\e[32m"
|
30
|
+
@color_end = "\e[0m"
|
31
|
+
|
32
|
+
@app_filename = name.downcase
|
33
|
+
@project_path = "#{Judojs.root_directory}#{proj_dir}"
|
34
|
+
@config = Judojs::Configuration.new @project_path, name
|
35
|
+
@manifest = Array['application',
|
36
|
+
'elements',
|
37
|
+
'lib',
|
38
|
+
'models',
|
39
|
+
'modules',
|
40
|
+
'plugins',
|
41
|
+
'tests']
|
42
|
+
end
|
43
|
+
|
44
|
+
def create
|
45
|
+
puts "#{@color_start}>>>#{@color_end} Creating the #{@config.name} project in #{@project_path}"
|
46
|
+
create_project_structure
|
47
|
+
@config.create
|
48
|
+
create_judo_lib_file
|
49
|
+
create_utility_lib_file
|
50
|
+
create_judo_application_file
|
51
|
+
import_javascripts
|
52
|
+
end
|
53
|
+
|
54
|
+
def update
|
55
|
+
get_modules
|
56
|
+
compile_modules
|
57
|
+
update_application_file
|
58
|
+
compress_application if @config.output == 'compressed'
|
59
|
+
puts "#{@color_start}>>>#{@color_end} application updated"
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_project_structure
|
63
|
+
Dir.mkdir "#{@project_path}" unless File.exists? "#{@project_path}"
|
64
|
+
|
65
|
+
@manifest.each do |folder|
|
66
|
+
puts "#{folder}/ created" unless File.exists? "#{@project_path}#{folder}"
|
67
|
+
Dir.mkdir "#{@project_path}#{folder}" unless File.exists? "#{@project_path}#{folder}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_judo_lib_file
|
72
|
+
judo_lib_secretary = Sprockets::Secretary.new(
|
73
|
+
:root => "#{Judojs.base_directory}",
|
74
|
+
:asset_root => "#{@config.asset_root}",
|
75
|
+
:load_path => ["repository"],
|
76
|
+
:source_files => ["repository/judojs/core/judo.js"]
|
77
|
+
)
|
78
|
+
|
79
|
+
judo_lib = judo_lib_secretary.concatenation
|
80
|
+
judo_lib.save_to "#{@project_path}lib/judo.js"
|
81
|
+
|
82
|
+
puts "lib/judo.js created"
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_utility_lib_file
|
86
|
+
utility_lib_secretary = Sprockets::Secretary.new(
|
87
|
+
:root => "#{Judojs.base_directory}",
|
88
|
+
:asset_root => "#{@config.asset_root}",
|
89
|
+
:load_path => ["repository"],
|
90
|
+
:source_files => ["repository/judojs/utilities/all.js"]
|
91
|
+
)
|
92
|
+
|
93
|
+
utility_lib = utility_lib_secretary.concatenation
|
94
|
+
utility_lib.save_to "#{@project_path}lib/utilities.js"
|
95
|
+
|
96
|
+
puts "lib/utilities.js created"
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_judo_application_file
|
100
|
+
filename = "#{@project_path}application/#{@app_filename}.js"
|
101
|
+
|
102
|
+
#puts File.exists?("#{@project_path}application/#{@app_filename}.js") ? "application/#{@app_filename}.js updated" : "application/#{@app_filename}.js created"
|
103
|
+
File.open(filename, "w+") do |file|
|
104
|
+
file << "//-- Judojs #{Time.now.to_s} --//\n"
|
105
|
+
file << File.open("#{@project_path}lib/judo.js", 'r').readlines.join('')
|
106
|
+
file << "\nvar #{@config.name} = new JudoApplication();"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def import_javascripts
|
111
|
+
File.copy "#{Judojs.base_directory}/repository/judojs/tests/index.html", "#{@project_path}tests"
|
112
|
+
File.copy "#{Judojs.base_directory}/repository/judojs/tests/judojs.test.js", "#{@project_path}tests"
|
113
|
+
File.copy "#{Judojs.base_directory}/repository/judojs/tests/judojs.utilities.test.js", "#{@project_path}tests"
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_modules
|
117
|
+
entries = Dir.entries "#{@project_path}modules"
|
118
|
+
@modules = entries.reject { |file| file.match(/^\./) }
|
119
|
+
end
|
120
|
+
|
121
|
+
def compile_modules
|
122
|
+
@modules.each do |module_file|
|
123
|
+
module_filename = Judojs::Helpers.create_module_filename module_file
|
124
|
+
create_module_file module_file, module_filename
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_module_file(module_file, module_name)
|
129
|
+
module_src = "#{@project_path}modules/#{module_file}"
|
130
|
+
|
131
|
+
judo_lib_secretary = Sprockets::Secretary.new(
|
132
|
+
:root => "#{Judojs.base_directory}",
|
133
|
+
:asset_root => "#{@config.asset_root}",
|
134
|
+
:load_path => ["repository"],
|
135
|
+
:source_files => ["#{module_src}"]
|
136
|
+
)
|
137
|
+
|
138
|
+
module_file = judo_lib_secretary.concatenation
|
139
|
+
message = File.exists?("#{@project_path}application/#{module_name}.js") ? "application/#{module_name}.js updated" : "application/#{module_name}.js created"
|
140
|
+
module_file.save_to "#{@project_path}application/#{module_name}.js"
|
141
|
+
judo_lib_secretary.install_assets
|
142
|
+
|
143
|
+
#puts message
|
144
|
+
end
|
145
|
+
|
146
|
+
def update_application_file
|
147
|
+
message = File.exists?("#{@project_path}application/#{@app_filename}.js") ? "application/#{@app_filename}.js updated" : "application/#{@app_filename}.js created"
|
148
|
+
|
149
|
+
content = String.new
|
150
|
+
content << "/* Judojs #{Time.now.to_s} */\n"
|
151
|
+
content << "//= require \"../lib/judo.js\"\n\n"
|
152
|
+
content << "\nvar #{@config.name} = new JudoApplication();"
|
153
|
+
|
154
|
+
filename = "#{@project_path}application/#{@app_filename}.js"
|
155
|
+
File.open(filename, "w+") do |file|
|
156
|
+
file << content
|
157
|
+
@config.autoload.each do |auto_file|
|
158
|
+
file << "\n\n/*---------- Judojs autoload #{auto_file} ----------*/"
|
159
|
+
file << "\n//= require #{auto_file}\n" if auto_file.match(/^\<.+\>$/)
|
160
|
+
file << "\n//= require \"#{auto_file}\"\n" if auto_file.match(/^[^\<].+|[^\>]$/)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
judo_lib_secretary = Sprockets::Secretary.new(
|
165
|
+
:root => "#{Judojs.base_directory}",
|
166
|
+
:asset_root => "#{@config.asset_root}",
|
167
|
+
:load_path => ["repository"],
|
168
|
+
:source_files => ["#{filename}"]
|
169
|
+
)
|
170
|
+
|
171
|
+
application_file = judo_lib_secretary.concatenation
|
172
|
+
judo_lib_secretary.install_assets
|
173
|
+
application_file.save_to "#{filename}"
|
174
|
+
|
175
|
+
#puts message
|
176
|
+
end
|
177
|
+
|
178
|
+
def compress_application
|
179
|
+
application = @project_path + 'application'
|
180
|
+
modules = Dir.entries(application)
|
181
|
+
modules.reject! { |file| file =~ /^\./ }
|
182
|
+
|
183
|
+
modules.each do |module_file|
|
184
|
+
full_path = application + "/#{module_file}"
|
185
|
+
uncompressed = File.open(full_path, "r").readlines.join('')
|
186
|
+
File.open(full_path, "w+") do |module_file|
|
187
|
+
module_file << JSMin.minify(uncompressed)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
data/lib/judojs.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Judojs
|
2
|
+
end
|
3
|
+
|
4
|
+
module Judojs
|
5
|
+
def version
|
6
|
+
'0.9.1'
|
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 :base_directory, :lib_directory, :root_directory, :repository_root
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
%w(dependencies configuration helpers project command jpm).each do |lib|
|
30
|
+
require "#{Judojs.lib_directory}/judojs/#{lib}"
|
31
|
+
end
|