sudojs-rails 0.2.4 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,42 +5,48 @@ Example:
5
5
  `rails g sudojs:class View foo#baz`
6
6
 
7
7
  Where `View` is a Class Object that this new Object will inherit from. Sudo.js itself
8
- will recognize 5 types:
8
+ will recognize 6 types:
9
9
 
10
10
  1. 'Base'
11
- 2. 'Container'
12
- 3. 'View'
13
- 4. 'ViewController'
14
- 5. 'Dataview'
11
+ 2. 'Model'
12
+ 3. 'Container'
13
+ 4. 'View'
14
+ 5. 'ViewController'
15
+ 6. 'Dataview'
15
16
 
16
17
  The inheritance for any of these will be set as `_.<Name>` as we assume sudo has taken the
17
18
  global `_` char as an alias. If the argument is any other string we assume you are inheriting
18
19
  from a custom class and pass it through as is.
19
20
 
20
-
21
21
  Where `foo#baz` *can* match a controller#action (like `home#show`) it does not
22
22
  have to. The controller argument (`foo`) allows the generator to place the file correctly and
23
23
  create/modify the correct manifest file. The name argument will be the proper name of the
24
- Class Object itself
24
+ Class Object itself.
25
25
 
26
- If a corresponding views/controller/name.html.* is found, a skeletal instantiation of the newly
27
- created View will be placed there
26
+ If a corresponding views/controller/name.html* is found, a skeletal instantiation of the newly
27
+ created View will be placed there.
28
28
 
29
- This will create:
29
+ This will create (or modify):
30
30
  app/
31
31
  assests/
32
+ stylesheets/
33
+ manifests/
34
+ foo.css
35
+ views/
36
+ foo/
37
+ baz.css(*)
32
38
  javascripts/
33
39
  manifests/
34
40
  foo.js
35
41
  views/
36
42
  foo/
37
- baz.js
43
+ baz.js(*)
38
44
 
39
45
  And modify (if found):
40
46
  app/
41
47
  views/
42
48
  foo/
43
- baz.html.*
49
+ baz.html(*)
44
50
 
45
51
  Note:
46
52
  If the `route` is application level (application#baz) the file will be placed
@@ -47,42 +47,77 @@ module Sudojs
47
47
  # expand the template to <destination>
48
48
  def copy_class_template
49
49
  if @is_application
50
- path = "app/assets/javascripts/application"
50
+ path = 'app/assets/javascripts/application'
51
+ css_path = 'app/assets/stylesheets/application'
51
52
  @path_to_object = namespace
52
53
  else
53
54
  path = "app/assets/javascripts/views/#{@c_name}"
55
+ css_path = "app/assets/stylesheets/views/#{@c_name}"
54
56
  @path_to_object = [namespace, '.', @c_camel].join('')
55
57
  # make sure the directory is present (create if not)
56
- ensure_cname_dir(path)
58
+ unless skip_css?
59
+ ensure_cname_dir(path, css_path)
60
+ else
61
+ ensure_cname_dir(path)
62
+ end
57
63
  end
58
64
 
59
- if use_coffee?
65
+ # js
66
+ if js_extension == '.js.coffee'
60
67
  template 'class.coffee.erb', "#{path}/#{@a_name}.js.coffee"
61
68
  else
62
- template 'class.js.erb', "#{path}/#{@a_name}.js"
69
+ template 'class.js.erb', "#{path}/#{@a_name}#{js_extension}"
70
+ end
71
+
72
+ # css
73
+ unless skip_css?
74
+ # new, blank file
75
+ create_file "#{css_path}/#{@a_name}#{css_extension}"
63
76
  end
64
77
  end
65
78
 
66
79
  def create_or_modify_manifest
80
+ js_pre = '//= '
81
+ css_pre = ' *= '
82
+ rest_app = "require application/#{@a_name}"
83
+ rest_view = "require views/#{@c_name}/#{@a_name}"
67
84
  filename = "app/assets/javascripts/manifests/#{@c_name}.js"
85
+ css_filename = "app/assets/stylesheets/manifests/#{@c_name}.css"
68
86
  if @is_application
69
- line = "//= require application/#{@a_name}"
87
+ line = js_pre + rest_app
88
+ css_line = css_pre + rest_app + "\n"
70
89
  else
71
- line = "//= require views/#{@c_name}/#{@a_name}"
90
+ line = js_pre + rest_view
91
+ css_line = css_pre + rest_view + "\n"
72
92
  end
73
93
 
94
+ # js
74
95
  if File.exist? filename
75
- # inject_into_file not needed here unless you were using a require tree
96
+ # inject_into_file not needed here as we do not use require_tree
76
97
  append_to_file filename, line
98
+ gsub_file filename, /^$\n/, ''
77
99
  else
78
100
  template 'manifest.js.erb', filename
101
+ gsub_file filename, /^$\n/, ''
102
+ end
103
+
104
+ # css
105
+ unless skip_css?
106
+ if File.exist? css_filename
107
+ inject_into_file css_filename, css_line, :before => '*/'
108
+ gsub_file css_filename, /^$\n/, ''
109
+ else
110
+ template 'manifest.css.erb', css_filename
111
+ gsub_file css_filename, /^$\n/, ''
112
+ end
79
113
  end
80
114
  end
81
115
 
82
116
  def modify_view_if_exists
83
- filename = "app/views/#{@c_name}/#{@a_name}.html.#{which_markup}"
117
+ filename = "app/views/#{@c_name}/#{@a_name}.html#{html_extension}"
84
118
  if File.exist? filename
85
- if use_coffee?
119
+ # TODO other pre-processors may need entries here
120
+ if js_extension == '.js.coffee'
86
121
  comment = '#'
87
122
  else
88
123
  comment = '//'
@@ -95,10 +130,11 @@ module Sudojs
95
130
 
96
131
  private
97
132
 
98
- def ensure_cname_dir(path)
99
- # if exists we will assume a directory
100
- unless File.exist? path
101
- empty_directory(path)
133
+ def ensure_cname_dir(*paths)
134
+ paths.each do |path|
135
+ unless File.directory? path
136
+ empty_directory path
137
+ end
102
138
  end
103
139
  end
104
140
 
@@ -0,0 +1,9 @@
1
+ /*
2
+ * This is a css manifest for the <%= @c_name%> controller
3
+ *
4
+ <% if @is_application %>
5
+ *= require application/<%= @a_name %>
6
+ <% else %>
7
+ *= require views/<%= @c_name %>/<%= @a_name %>
8
+ <% end %>
9
+ */
@@ -1,3 +1,5 @@
1
+ // This is a js manifest for the <%= @c_name%> controller
2
+ //
1
3
  <% if @is_application %>
2
4
  //= require application/<%= @a_name %>
3
5
  <% else %>
@@ -14,12 +14,21 @@ module Sudojs
14
14
  CFG['which_sudo']
15
15
  end
16
16
 
17
- def which_markup
18
- CFG['which_markup']
17
+ def html_extension
18
+ CFG['html_extension']
19
19
  end
20
20
 
21
- def use_coffee?
22
- CFG['use_coffee']
21
+ def js_extension
22
+ CFG['js_extension']
23
+ end
24
+
25
+ # do not create any files for (s)css
26
+ def skip_css?
27
+ CFG['skip_css']
28
+ end
29
+
30
+ def css_extension
31
+ CFG['css_extension']
23
32
  end
24
33
 
25
34
  def camelize(what)
@@ -2,7 +2,7 @@ Description:
2
2
  Install sudo.js along with it's particular directory hierarchy.
3
3
 
4
4
  Example:
5
- rails g sudojs:install namespace [which_sudo] [which_markup] [use_coffee]
5
+ rails g sudojs:install namespace [which_sudo] [html_extension] [js_extension] [css_extension] [--skip-css=true/false]
6
6
 
7
7
  The only mandatory argument is the initial `namespace`.
8
8
 
@@ -10,12 +10,19 @@ Example:
10
10
  1. `which_sudo` => which version of sudo.js are you loading? As sudo.js can be rebuilt into any number
11
11
  of custom configurations, indicate here what name should be placed into the application manifest.
12
12
  Defaults to 'sudo-x' if omitted.
13
- 2. `which_markup` => defaults to `erb`.
14
- 3. `use_coffee` => defaults to `false` pass `true` if you are of the coffee persuasion.
13
+ 2. `html_extension` => Use the full extension, i.e. `.haml`. defaults to `.erb`.
14
+ 3. `js_extension` => defaults to `.js` pass `.js.coffee` if you are of the coffee persuasion.
15
+ 4. `css_extension` => defaults to `.css`. Sass for example would need `.css.scss`
16
+
17
+ NOTE: to skip any and all generating of css files pass the option `--skip-css=true` when invoking the install generator.
18
+ Obviously, you could then leave the `css_extension` argument out. The option defaults to false.
15
19
 
16
20
  This will create:
17
21
  app/
18
22
  assets/
23
+ stylesheets/
24
+ manifests/
25
+ application.css
19
26
  javascripts/
20
27
  application/
21
28
  yourNamespace.js
@@ -4,29 +4,54 @@ module Sudojs
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  argument :which_sudo_arg, :type => :string, :default => 'sudo-x'
7
- argument :which_markup_arg, :type => :string, :default => 'erb'
8
- argument :use_coffee_arg, :type => :string, :default => 'false'
7
+ argument :html_extension_arg, :type => :string, :default => '.erb'
8
+ argument :js_extension_arg, :type => :string, :default => '.js'
9
+ argument :css_extension_arg, :type => :string, :default => '.css'
10
+
11
+ class_option :skip_css_opt, :type => :boolean, :aliases => "--skip-css", :default => false,
12
+ :desc => 'Skip the generation of any css files along with js'
9
13
 
10
14
  def create_yaml
15
+ if options[:skip_css]
16
+ @skip_css = 'true'
17
+ else
18
+ @skip_css = 'false'
19
+ end
11
20
  template 'sudo_js.erb.yml', 'config/sudo_js.yml'
12
21
  end
13
22
 
14
23
  def create_dir_structure
15
24
  %W{application manifests views}.each do |dir|
16
- empty_directory "app/assets/javascripts/#{dir}"
25
+ directory = "app/assets/javascripts/#{dir}"
26
+ css_directory = "app/assets/stylesheets/#{dir}"
27
+ unless File.directory? directory
28
+ empty_directory directory
29
+ end
30
+
31
+ unless options[:skip_css]
32
+ unless File.directory? css_directory
33
+ empty_directory css_directory
34
+ end
35
+ end
17
36
  end
18
37
  end
19
38
 
20
39
  def place_install_files
21
40
  template 'app_manifest.js.erb', 'app/assets/javascripts/manifests/application.js'
22
-
23
- unless use_coffee_arg == 'false'
41
+ unless options[:skip_css]
42
+ template 'app_manifest.css.erb', 'app/assets/stylesheets/manifests/application.js'
43
+ end
44
+
45
+ # TODO templates for other javascript pre-processors
46
+ if js_extension_arg == '.js.coffee'
24
47
  template 'namespace.coffee.erb', "app/assets/javascripts/application/#{name}.js.coffee"
25
48
  template 'model.coffee.erb', 'app/assets/javascripts/application/model.js.coffee'
26
49
  else
27
- template 'namespace.js.erb', "app/assets/javascripts/application/#{name}.js"
28
- template 'model.js.erb', 'app/assets/javascripts/application/model.js'
50
+ # for now any other js flavor gets the baseline .js
51
+ template 'namespace.js.erb', "app/assets/javascripts/application/#{name}#{js_extension_arg}"
52
+ template 'model.js.erb', "app/assets/javascripts/application/model#{js_extension_arg}"
29
53
  end
54
+
30
55
  end
31
56
 
32
57
  end
@@ -0,0 +1,5 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ */
@@ -1,3 +1,6 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
1
4
  //= require jquery_ujs
2
5
  //= require <%= which_sudo_arg %>
3
6
  //= require application/<%= name %>
@@ -5,7 +5,13 @@ js_namespace: <%= name %>
5
5
  which_sudo: <%= which_sudo_arg %>
6
6
 
7
7
  # erb or haml or ...?
8
- which_markup: <%= which_markup_arg %>
8
+ html_extension: <%= html_extension_arg %>
9
9
 
10
10
  # coffee?
11
- use_coffee: <%= use_coffee_arg %>
11
+ js_extension: <%= js_extension_arg %>
12
+
13
+ # create (S)css files too?
14
+ skip_css: <%= @skip_css %>
15
+
16
+ # sass?
17
+ css_extension: <%= css_extension_arg %>
@@ -1,3 +1,3 @@
1
1
  module Sudojs
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -487,13 +487,17 @@ sudo.Container.prototype.send = function send(/*args*/) {
487
487
  // a shortcut for `this.$el.find(selector)`
488
488
  //
489
489
  // `param` {string|element|jQuery} `el`. Otional el for the View instance.
490
- // `param` {Object} `data`. Optional data object which becomes the initial state
491
- // of a new model located at `this.model`.
490
+ // `param` {Object} `data`. Optional data object-literal which becomes the initial state
491
+ // of a new model located at `this.model`. Also can be a reference to an existing sudo.Model instance
492
492
  //
493
493
  // `constructor`
494
494
  sudo.View = function(el, data) {
495
495
  sudo.Container.call(this);
496
- if(data) this.model = new sudo.Model(data);
496
+ // allow model instance to be passed in as well
497
+ if(data) {
498
+ this.model = data.role === 'model' ? data :
499
+ this.model = new sudo.Model(data);
500
+ }
497
501
  this.setEl(el);
498
502
  if(this.role === 'view') this.init();
499
503
  };
@@ -1418,7 +1422,7 @@ sudo.delegates.Data.prototype.filter = function(obj) {
1418
1422
  // `private`
1419
1423
  sudo.delegates.Data.prototype.role = 'data';
1420
1424
 
1421
- sudo.version = "0.9.0";
1425
+ sudo.version = "0.9.1";
1422
1426
  window.sudo = sudo;
1423
1427
  if(typeof window._ === "undefined") window._ = sudo;
1424
1428
  }).call(this, this);
@@ -487,13 +487,17 @@ sudo.Container.prototype.send = function send(/*args*/) {
487
487
  // a shortcut for `this.$el.find(selector)`
488
488
  //
489
489
  // `param` {string|element|jQuery} `el`. Otional el for the View instance.
490
- // `param` {Object} `data`. Optional data object which becomes the initial state
491
- // of a new model located at `this.model`.
490
+ // `param` {Object} `data`. Optional data object-literal which becomes the initial state
491
+ // of a new model located at `this.model`. Also can be a reference to an existing sudo.Model instance
492
492
  //
493
493
  // `constructor`
494
494
  sudo.View = function(el, data) {
495
495
  sudo.Container.call(this);
496
- if(data) this.model = new sudo.Model(data);
496
+ // allow model instance to be passed in as well
497
+ if(data) {
498
+ this.model = data.role === 'model' ? data :
499
+ this.model = new sudo.Model(data);
500
+ }
497
501
  this.setEl(el);
498
502
  if(this.role === 'view') this.init();
499
503
  };
@@ -804,7 +808,7 @@ sudo.ext.observable = {
804
808
  return this.deliverChangeRecords();
805
809
  }
806
810
  };
807
- sudo.version = "0.9.0";
811
+ sudo.version = "0.9.1";
808
812
  window.sudo = sudo;
809
813
  if(typeof window._ === "undefined") window._ = sudo;
810
814
  }).call(this, this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sudojs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-06 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -44,10 +44,12 @@ files:
44
44
  - lib/generators/sudojs/class/class_generator.rb
45
45
  - lib/generators/sudojs/class/templates/class.coffee.erb
46
46
  - lib/generators/sudojs/class/templates/class.js.erb
47
+ - lib/generators/sudojs/class/templates/manifest.css.erb
47
48
  - lib/generators/sudojs/class/templates/manifest.js.erb
48
49
  - lib/generators/sudojs/helpers.rb
49
50
  - lib/generators/sudojs/install/USAGE
50
51
  - lib/generators/sudojs/install/install_generator.rb
52
+ - lib/generators/sudojs/install/templates/app_manifest.css.erb
51
53
  - lib/generators/sudojs/install/templates/app_manifest.js.erb
52
54
  - lib/generators/sudojs/install/templates/model.coffee.erb
53
55
  - lib/generators/sudojs/install/templates/model.js.erb
@@ -76,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
78
  version: '0'
77
79
  segments:
78
80
  - 0
79
- hash: 4176419229015017956
81
+ hash: 564744646304978931
80
82
  required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  none: false
82
84
  requirements:
@@ -85,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: 4176419229015017956
90
+ hash: 564744646304978931
89
91
  requirements: []
90
92
  rubyforge_project:
91
93
  rubygems_version: 1.8.24