ninjs 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +64 -0
  3. data/Rakefile +4 -1
  4. data/VERSION +1 -1
  5. data/bin/ninjs +14 -5
  6. data/lib/ninjs.rb +0 -3
  7. data/lib/ninjs/command.rb +67 -110
  8. data/lib/ninjs/configuration.rb +33 -39
  9. data/lib/ninjs/project.rb +14 -31
  10. data/ninjs.conf +7 -0
  11. data/ninjs.gemspec +63 -5
  12. data/repository/jquery/1.5.js +16 -0
  13. data/repository/jquery/latest.js +1 -1
  14. data/repository/jquery/mobile/1.0a3.js +123 -0
  15. data/repository/jquery/mobile/1.0a3/assets/css/jquery.mobile.css +1652 -0
  16. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/ajax-loader.png +0 -0
  17. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-off.png +0 -0
  18. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-on.png +0 -0
  19. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-off.png +0 -0
  20. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-on.png +0 -0
  21. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icon-search-black.png +0 -0
  22. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-black.png +0 -0
  23. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-white.png +0 -0
  24. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-black.png +0 -0
  25. data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-white.png +0 -0
  26. data/repository/jquery/mobile/latest.js +1 -0
  27. data/spec/fixtures/global.js +7 -0
  28. data/spec/fixtures/global.module.js +7 -0
  29. data/spec/fixtures/myapplication.js +576 -0
  30. data/spec/fixtures/nin.js +573 -0
  31. data/spec/fixtures/ninjs.conf +6 -0
  32. data/spec/fixtures/test.elements.js +4 -0
  33. data/spec/fixtures/test.js +15 -0
  34. data/spec/fixtures/test.model.js +3 -0
  35. data/spec/fixtures/test.module.js +10 -0
  36. data/spec/fixtures/updated.myapplication.js +27 -0
  37. data/spec/fixtures/utilities.js +162 -0
  38. data/spec/ninjs_spec.rb +257 -0
  39. data/spec/spec_helper.rb +2 -1
  40. data/tmp/ff9e83aa019b712b90200b8d1b8fa0c7e14576af.json +1 -0
  41. data/tmp/metric_fu/_data/20110305.yml +1548 -0
  42. data/tmp/metric_fu/output/bluff-min.js +1 -0
  43. data/tmp/metric_fu/output/churn.html +692 -0
  44. data/tmp/metric_fu/output/excanvas.js +35 -0
  45. data/tmp/metric_fu/output/flay.html +566 -0
  46. data/tmp/metric_fu/output/flay.js +11 -0
  47. data/tmp/metric_fu/output/flog.html +2392 -0
  48. data/tmp/metric_fu/output/flog.js +12 -0
  49. data/tmp/metric_fu/output/hotspots.html +3607 -0
  50. data/tmp/metric_fu/output/index.html +572 -0
  51. data/tmp/metric_fu/output/js-class.js +1 -0
  52. data/tmp/metric_fu/output/lib_ninjs.rb.html +49 -0
  53. data/tmp/metric_fu/output/lib_ninjs_command.rb.html +137 -0
  54. data/tmp/metric_fu/output/lib_ninjs_configuration.rb.html +107 -0
  55. data/tmp/metric_fu/output/lib_ninjs_dependencies.rb.html +34 -0
  56. data/tmp/metric_fu/output/lib_ninjs_helpers.rb.html +34 -0
  57. data/tmp/metric_fu/output/lib_ninjs_manifest.rb.html +27 -0
  58. data/tmp/metric_fu/output/lib_ninjs_project.rb.html +236 -0
  59. data/tmp/metric_fu/output/rails_best_practices.js +11 -0
  60. data/tmp/metric_fu/output/rcov.html +566 -0
  61. data/tmp/metric_fu/output/rcov.js +11 -0
  62. data/tmp/metric_fu/output/reek.html +1294 -0
  63. data/tmp/metric_fu/output/reek.js +20 -0
  64. data/tmp/metric_fu/output/roodi.html +599 -0
  65. data/tmp/metric_fu/output/roodi.js +11 -0
  66. data/tmp/metric_fu/report.yml +1548 -0
  67. data/tmp/metric_fu/scratch/rcov/rcov.txt +1 -0
  68. metadata +94 -27
  69. data/spec/test_spec.rb +0 -5
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gem "sprockets", ">= 0"
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
11
11
  group :development do
12
+ gem "metric_fu", ">= 0"
12
13
  gem "shoulda", ">= 0"
13
14
  gem "bundler", "~> 1.0.0"
14
15
  gem "jeweler", "~> 1.5.2"
data/Gemfile.lock CHANGED
@@ -1,16 +1,71 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ Saikuro (1.1.0)
5
+ abstract (1.0.0)
6
+ activesupport (3.0.5)
7
+ arrayfields (4.7.4)
8
+ chronic (0.3.0)
9
+ churn (0.0.13)
10
+ chronic (>= 0.2.3)
11
+ hirb
12
+ json_pure
13
+ main
14
+ ruby_parser (~> 2.0.4)
15
+ sexp_processor (~> 3.0.3)
16
+ colored (1.2)
4
17
  diff-lcs (1.1.2)
18
+ erubis (2.6.6)
19
+ abstract (>= 1.0.0)
20
+ fattr (2.2.0)
21
+ flay (1.4.2)
22
+ ruby_parser (~> 2.0)
23
+ sexp_processor (~> 3.0)
24
+ flog (2.5.1)
25
+ ruby_parser (~> 2.0)
26
+ sexp_processor (~> 3.0)
5
27
  fssm (0.2.2)
6
28
  git (1.2.5)
29
+ haml (3.0.25)
30
+ hirb (0.4.0)
31
+ i18n (0.5.0)
7
32
  jeweler (1.5.2)
8
33
  bundler (~> 1.0.0)
9
34
  git (>= 1.2.5)
10
35
  rake
11
36
  jsmin (1.0.1)
37
+ json_pure (1.5.1)
38
+ main (4.4.0)
39
+ arrayfields (>= 4.7.4)
40
+ fattr (>= 2.1.0)
41
+ metric_fu (2.1.1)
42
+ Saikuro (>= 1.1.0)
43
+ activesupport (>= 2.0.0)
44
+ chronic (~> 0.3.0)
45
+ churn (>= 0.0.7)
46
+ flay (>= 1.2.1)
47
+ flog (>= 2.3.0)
48
+ rails_best_practices (>= 0.6.4)
49
+ rcov (>= 0.8.3.3)
50
+ reek (>= 1.2.6)
51
+ roodi (>= 2.1.0)
52
+ syntax
53
+ rails_best_practices (0.7.1)
54
+ activesupport
55
+ colored (~> 1.2)
56
+ erubis (~> 2.6.6)
57
+ haml (~> 3.0.18)
58
+ i18n
59
+ ruby-progressbar (~> 0.0.9)
60
+ ruby_parser (~> 2.0.4)
12
61
  rake (0.8.7)
13
62
  rcov (0.9.9)
63
+ reek (1.2.8)
64
+ ruby2ruby (~> 1.2)
65
+ ruby_parser (~> 2.0)
66
+ sexp_processor (~> 3.0)
67
+ roodi (2.1.0)
68
+ ruby_parser
14
69
  rspec (2.4.0)
15
70
  rspec-core (~> 2.4.0)
16
71
  rspec-expectations (~> 2.4.0)
@@ -20,8 +75,16 @@ GEM
20
75
  diff-lcs (~> 1.1.2)
21
76
  rspec-mocks (2.4.0)
22
77
  rubikon (0.5.3)
78
+ ruby-progressbar (0.0.9)
79
+ ruby2ruby (1.2.5)
80
+ ruby_parser (~> 2.0)
81
+ sexp_processor (~> 3.0)
82
+ ruby_parser (2.0.6)
83
+ sexp_processor (~> 3.0)
84
+ sexp_processor (3.0.5)
23
85
  shoulda (2.11.3)
24
86
  sprockets (1.0.2)
87
+ syntax (1.0.0)
25
88
 
26
89
  PLATFORMS
27
90
  ruby
@@ -31,6 +94,7 @@ DEPENDENCIES
31
94
  fssm
32
95
  jeweler (~> 1.5.2)
33
96
  jsmin
97
+ metric_fu
34
98
  rcov
35
99
  rspec
36
100
  rubikon
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ require 'jeweler'
13
13
  Jeweler::Tasks.new do |gem|
14
14
  gem.name = "ninjs"
15
15
  gem.homepage = "http://github.com/textnotspeech/ninjs"
16
+ gem.rubyforge_project = "nowarning"
16
17
  gem.license = "MIT"
17
18
  gem.summary = %Q{ninjs is a command line application to help you write clean, modular javascript applications.}
18
19
  gem.description = %Q{Ninjs is a ruby application and small javascript framework that helps you build clean, modular javascript applications. Ninjs encourages "Good Parts" best practices and the Crockford school Module pattern (http://www.crockford.com/). The ninjs command line application is an automatic compiler, written in ruby, and based on the Sprockets library (http://getsprockets.org/).}
@@ -57,4 +58,6 @@ namespace :ndoc do
57
58
  puts output
58
59
  end
59
60
 
60
- end
61
+ end
62
+
63
+ require 'metric_fu'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.1
1
+ 0.11.0
data/bin/ninjs CHANGED
@@ -42,11 +42,20 @@ class NinjsConsole < Rubikon::Application::Base
42
42
  Ninjs::Command.import
43
43
  end
44
44
 
45
- option :directory, :dir do
46
- @directory = dir
47
- end
48
- option :p => :directory
45
+ option :withdir, :path
46
+ flag :p => :withdir
49
47
  command :create, :app_name do
50
- Ninjs::Command.create(app_name, @directory)
48
+ directory = (given? :p) ? withdir.path : false
49
+ Ninjs::Command.create(app_name, directory)
50
+ end
51
+
52
+ option :e
53
+ option :m
54
+ command :generate, :object, :obj_name do
55
+ Ninjs::Command.generate('elements', obj_name) if e.given?
56
+ Ninjs::Command.generate('model', obj_name) if m.given?
57
+ elements = e.given? || false
58
+ models = m.given? || false
59
+ Ninjs::Command.generate(object, obj_name, elements, models)
51
60
  end
52
61
  end
data/lib/ninjs.rb CHANGED
@@ -1,6 +1,3 @@
1
- module Ninjs
2
- end
3
-
4
1
  module Ninjs
5
2
  def version
6
3
  '0.10.1'
data/lib/ninjs/command.rb CHANGED
@@ -4,127 +4,54 @@ module Ninjs
4
4
  require "fssm"
5
5
  project_path = Dir.getwd << '/'
6
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)
7
+ puts "\e[32m>>>\e[0m Ninjs are watching for changes. Press Ctrl-C to stop."
8
+ project = Ninjs::Project.new
11
9
  project.update
12
10
 
13
- # TODO make this smaller using globs
14
- FSSM.monitor do
15
- path "#{Ninjs.base_directory}/repository" do
16
- glob "**/*.js"
17
-
18
- update do |base, relative|
19
- puts "#{color_start}<<<#{color_end} ninjs repository updated #{relative}"
20
- project.update
21
- end
22
-
23
- create do |base, relative|
24
- puts "#{relative} created in repository"
25
- project.update
26
- end
27
- end
28
-
29
- path "#{project_path}elements" do
30
- glob "**/*.js"
31
-
32
- update do |base, relative|
33
- puts "#{color_start}<<<#{color_end} change detected in #{relative}"
34
- project.update
35
- end
36
-
37
- create do |base, relative|
38
- puts "#{relative} created"
39
- project.update
40
- end
41
- end
42
-
43
- path "#{project_path}models" do
44
- glob "**/*.js"
45
-
46
- update do |base, relative|
47
- puts "#{@color_start}<<<#{@color_end} change detected in #{relative}"
48
- project.update
49
- end
50
-
51
- create do |base, relative|
52
- puts "#{relative} created"
53
- project.update
54
- end
55
- end
56
-
57
- path "#{project_path}modules" do
58
- glob "**/*.js"
59
-
60
- update do |base, relative|
61
- puts "#{color_start}<<<#{color_end} change detected in #{relative}"
62
- project.update
63
- end
64
-
65
- create do |base, relative|
66
- puts "#{relative} created"
67
- project.update
68
- end
69
- end
70
-
71
- path "#{project_path}lib" do
72
- glob "**/*.js"
73
-
74
- update do |base, relative|
75
- puts "#{color_start}<<<#{color_end} change detected in #{relative}"
76
- project.config.read
77
- project.update_application_file
78
- project.update
79
- end
80
-
81
- create do |base, relative|
82
- puts "+++ created #{relative}"
83
- project.update
84
- end
85
- end
86
-
87
- path "#{project_path}plugins" do
88
- glob "**/*.js"
89
-
90
- update do |base, relative|
91
- puts "#{color_start}<<<#{color_end} change detected in #{relative}"
92
- project.config.read
93
- project.update_application_file
94
- project.update
95
- end
96
-
97
- create do |base, relative|
98
- puts "+++ created #{relative}"
99
- project.update
100
- end
101
- end
102
-
103
- path "#{project_path}" do
104
- glob "**/*.conf"
105
-
106
- update do |base, relative|
107
- puts "#{color_start}<<<#{color_end} change detected in #{relative}"
108
- project.config.read
109
- project.update_application_file
110
- project.update
111
- end
112
- end
113
-
114
- end
115
-
11
+ watch_dirs = Ninjs::Manifest.directories.reject { |dir| dir.match(/application|tests/) }
12
+ watch_hash = Hash.new
13
+
14
+ watch_dirs.each do |dir|
15
+ watch_hash["#{project_path}#{dir}"] = "**/*.js"
16
+ end
17
+
18
+ watch_hash[project_path] = "**/*.conf"
19
+ watch_hash["#{Ninjs.base_directory}/repository"] = "**/*.js"
20
+
21
+ FSSM.monitor do
22
+
23
+ watch_hash.each do |dir, g|
24
+
25
+ path "#{dir}" do
26
+ glob g
27
+
28
+ update do |base, relative|
29
+ puts "\e[33m<<<\e[0m change detected in #{relative}"
30
+ project.update
31
+ end
32
+
33
+ create do |base, relative|
34
+ puts "\e[33m+++\e[0m #{relative} created"
35
+ project.update
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
116
43
  end
117
44
 
118
45
  def create(name, directory = false)
119
46
  raise 'you must specify a project name: ninjs create ProjectName' if name.nil?
120
- project = directory ? Ninjs::Project.new(name, directory) : Ninjs::Project.new(name)
47
+ project = directory ? Ninjs::Project.new(directory, name) : Ninjs::Project.new('/', name)
121
48
  project.create
122
49
  end
123
50
 
124
51
  def compile
125
52
  project_path = Dir.getwd << '/'
126
53
  raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
127
- project = Ninjs::Project.init_with_config(project_path)
54
+ project = Ninjs::Project.new
128
55
  project.update
129
56
  end
130
57
 
@@ -155,7 +82,37 @@ Example:
155
82
  ninjs watch
156
83
  DOC
157
84
  end
85
+
86
+ def generate(object, name, create_elements = false, create_models = false, elements = false, models = false)
87
+ begin
88
+ project_path = Dir.getwd << '/'
89
+ raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}ninjs.conf"
90
+ project = Ninjs::Project.new
91
+ if object === 'module'
92
+ File.open "#{project_path}modules/#{name.downcase}.module.js", "w" do |file|
93
+ file << project.config.name + ".add_module('" + name + "');\n\n"
94
+ file << '//= require "../elements/' + name.downcase + '.elements.js"' + "\n\n" if elements
95
+ file << '//= require "../models/' + name.downcase + '.model.js"' + "\n\n" if models
96
+ file << project.config.name + "." + name + ".actions = function() {\n\n}\n\n"
97
+ file << project.config.name + "." + name + ".run();"
98
+ puts "+++ created #{name.downcase}.module.js"
99
+ end unless File.exists? "#{project_path}modules/#{name.downcase}.module.js"
100
+ elsif object === 'elements'
101
+ File.open("#{project_path}elements/#{name.downcase}" + ".elements.js", "w") do |file|
102
+ file << project.config.name + "." + name + ".elements(function({\n\n}));"
103
+ puts "+++ created #{name.downcase}.elements.js"
104
+ end unless File.exists? "#{project_path}elements/#{name.downcase}.elements.js"
105
+ elsif object === 'model'
106
+ File.open "#{project_path}models/#{name.downcase}.model.js", "w" do |file|
107
+ file << project.config.name + "." + name + ".set_data({});"
108
+ puts "+++ created #{name.downcase}.model.js"
109
+ end unless File.exists? "#{project_path}models/#{name.downcase}.model.js"
110
+ end
111
+ rescue
112
+ # TODO rescue this
113
+ end
114
+ end
158
115
 
159
- module_function :create, :watch, :compile, :help, :import
116
+ module_function :create, :watch, :compile, :help, :import, :generate
160
117
  end
161
118
  end
@@ -2,7 +2,6 @@ module Ninjs
2
2
  class Configuration
3
3
 
4
4
  attr_reader :name,
5
- :project_path,
6
5
  :app_filename,
7
6
  :directory,
8
7
  :output,
@@ -11,41 +10,42 @@ module Ninjs
11
10
  :config_path,
12
11
  :asset_root,
13
12
  :base_url,
14
- :tests_path
13
+ :test_path
15
14
 
16
- def initialize(project_path, name = 'NinjsApplication')
15
+ def initialize(project_path, name = '')
16
+ @project_path = project_path
17
17
  @defaults = {
18
18
  :name => name,
19
- :project_path => project_path,
20
- :asset_root => project_path,
19
+ :app_filename => name.gsub(/\s|\-|\./, '').downcase,
21
20
  :output => 'expanded',
22
21
  :dependencies => ['<jquery/latest>'],
23
22
  :autoload => ['<ninjs/utilities/all>'],
24
23
  :base_url => 'http://www.example.com/',
25
- :tests_path => 'tests/'
24
+ :test_path => 'tests/'
26
25
  }
27
26
 
28
27
  @defaults.each do |label, setting|
29
28
  instance_variable_set("@#{label}", setting)
30
29
  end
30
+
31
+ if File.exists? "#{@project_path}ninjs.conf"
32
+ read
33
+ end
31
34
  end
32
35
 
33
36
  def create
34
- default_content = conf_content @defaults
37
+ options = @defaults
38
+ options.delete :app_filename
39
+ default_content = conf_content options
35
40
  create_conf_file default_content
36
41
  end
37
42
 
38
43
  def conf_content(options)
39
- content = <<-CONF
40
- name: #{options[:name]}
41
- project_path: #{options[:project_path]}
42
- asset_root: #{options[:project_path]}
43
- output: #{options[:output]}
44
- dependencies: [#{options[:dependencies].join(', ')}]
45
- autoload: [#{options[:autoload].join(', ')}]
46
- base_url: #{options[:base_url]}
47
- tests_path: #{options[:tests_path]}
48
- CONF
44
+ content = String.new
45
+ options.each do |option, value|
46
+ content << "#{option}: #{value}\n"
47
+ end
48
+ content
49
49
  end
50
50
 
51
51
  def create_conf_file(content)
@@ -57,37 +57,31 @@ tests_path: #{options[:tests_path]}
57
57
  end
58
58
 
59
59
  def update
60
- content = conf_content({
60
+ options = {
61
61
  :name => @name,
62
- :project_path => @project_path,
63
- :asset_root => @project_path,
62
+ :asset_root => @asset_root,
64
63
  :output => @output,
65
64
  :dependencies => @dependencies,
66
65
  :autoload => @autoload,
67
66
  :base_url => @base_url,
68
- :tests_path => @tests_path
69
- })
67
+ :test_path => @test_path
68
+ }
69
+ options.reject! { |option| option.nil? }
70
+
71
+ content = conf_content options
70
72
  create_conf_file content
71
73
  end
72
74
 
73
75
  def read
74
- begin
75
- raise IOError, "#{@project_path}ninjs.conf does not exist", caller unless File.exists? "#{@project_path}ninjs.conf"
76
- config = YAML.load_file("#{@project_path}ninjs.conf")
77
-
78
- @project_path = config['project_path']
79
- @asset_root = config['asset_root']
80
- @name = config['name']
81
- @app_filename = config['name'].downcase
82
- @output = config['output']
83
- @dependencies = config['dependencies'] || Array.new
84
- @autoload = config['autoload'] || Array.new
85
- @base_url = config['base_url'] || 'http://www.example.com/'
86
- @tests_path = config['tests_path'] || 'tests/'
87
- rescue IOError => e
88
- puts e.message
89
- puts e.backtrace.inspect
90
- end
76
+ config = YAML.load_file("#{@project_path}ninjs.conf")
77
+ @asset_root = config['asset_root'] unless config['asset_root'].nil?
78
+ @name = config['name']
79
+ @app_filename = config['name'].downcase
80
+ @output = config['output']
81
+ @dependencies = config['dependencies'] || Array.new
82
+ @autoload = config['autoload'] || Array.new
83
+ @base_url = config['base_url'] || 'http://www.example.com/'
84
+ @test_path = config['test_path'] || 'tests/'
91
85
  end
92
86
 
93
87
  end