ng_on_rails 0.0.3.5 → 0.0.3.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4dbd24da05c3703028c56e9e886bbad00d9bbfb
4
- data.tar.gz: dae75d2a092dfdb1476aa085b706ebaeb8e93adf
3
+ metadata.gz: 83a14652f6c74791f9d5afaab7882486853cb1c6
4
+ data.tar.gz: bc5ae54a788ff9f45458b9da672f51ca22eec70a
5
5
  SHA512:
6
- metadata.gz: e45f74e69948b5a4898ce60f597ba32210e24e9d18d2c10d2acb45830b9c2193fe457c8175de7b41657333693cc1c9a53f0ef069a4693d108753066fdfa84de6
7
- data.tar.gz: 52de3d3c9eee0a6e52be64f4b12e3fe52d89fc81bcdb80b51448ef4c65927edbd26b258ac7ee7dc032eb42e8e30df3bf83b8ecaaf1144cd810a4e2885654cfe8
6
+ metadata.gz: b9c7d97aa5e36afc112d466752a4ffb4509c288894b2f0fc0a2b8707e27e169183e336ca57e1e8d3cd6b334384b97b334148888036d28d767025fad2d1ebc4b3
7
+ data.tar.gz: d053de5c3e7c2cf39ec58965f59b6430ead35998865b28dba6cfabfe534768d67b7844c59d798ec6adfa41b036aac3386b68f6d0a33bd62353640d1a464333b5
data/README.md CHANGED
@@ -40,6 +40,9 @@ In your layout below the `javascript_include_tag "application"` load the Rails-s
40
40
 
41
41
  NgOnRails is now up and running!
42
42
 
43
+ _Instructions for using NgOnRails with a **Rails Engine** can be found [here](https://github.com/brookisme/ng_on_rails/wiki/Engines)._
44
+
45
+
43
46
  <a name="#ngor_app_note"></a>
44
47
  ##### Note: NgOnRailsApp
45
48
  An angular-app, NgOnRailsApp, is automatically created if it doesn't already exsit
@@ -1,6 +1,6 @@
1
1
  class NgOnRailsController < ApplicationController
2
2
  def template
3
3
  @path = params[:path]
4
- render template: '/angular_app/' + @path, layout: nil
4
+ render template: "/#{NgOnRails.engine_path}angular_app/" + @path, layout: nil
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'ng_on_rails_generator')
2
2
  module NgOnRails
3
3
  class ControllerGenerator < NgOnRails::NgOnRailsGenerator
4
4
  desc "Creates NgOnRails-style AngularJS Controller"
5
- argument :model_name, type: :string, required: false, desc: "model name"
5
+ argument :full_model_name, type: :string, required: false, desc: "model name"
6
6
 
7
7
  def self.source_root
8
8
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
@@ -11,11 +11,11 @@ module NgOnRails
11
11
  def generate_controller
12
12
  if model_name.blank?
13
13
  option_copy_file "#{ControllerGenerator.source_root}/app_controller_template.js.coffee",
14
- "app/assets/javascripts/angular_app/controllers/app_controller.js.coffee",
14
+ "app/assets/javascripts/#{module_path}angular_app/controllers/app_controller.js.coffee",
15
15
  "app controller"
16
16
  else
17
17
  option_copy_file "#{ControllerGenerator.source_root}/controller_template.js.erb",
18
- "app/assets/javascripts/angular_app/controllers/#{plural_name}_controller.js.coffee",
18
+ "app/assets/javascripts/#{module_path}angular_app/controllers/#{plural_name}_controller.js.coffee",
19
19
  "#{plural_name} controller",
20
20
  true
21
21
  end
@@ -23,12 +23,5 @@ module NgOnRails
23
23
 
24
24
  private
25
25
 
26
- #
27
- # View Helpers
28
- #
29
-
30
- def path_to_index_page
31
- Rails.application.routes.url_helpers.send("#{plural_name}_path")
32
- end
33
26
  end
34
27
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'ng_on_rails_generator')
2
2
  module NgOnRails
3
3
  class JbuilderGenerator < NgOnRails::NgOnRailsGenerator
4
4
  desc "Creates jbuilder files in rails-views"
5
- argument :model_name, type: :string, required: true, desc: "model name"
5
+ argument :full_model_name, type: :string, required: true, desc: "model name"
6
6
  argument :attributes, type: :array, required: false, desc: "list of attributes in json"
7
7
 
8
8
  def self.source_root
@@ -10,22 +10,22 @@ module NgOnRails
10
10
  end
11
11
 
12
12
  def generate_index
13
- option_create "app/views/#{plural_name}/index.json.jbuilder",
14
- "json.partial! '#{plural_name}/#{plural_name}.json', #{plural_name}: @#{plural_name}",
13
+ option_create "app/views/#{module_path}#{plural_name}/index.json.jbuilder",
14
+ "json.partial! '#{module_path}#{plural_name}/#{plural_name}.json', #{plural_name}: @#{plural_name}",
15
15
  "index jbuilder"
16
16
  end
17
17
  def generate_show
18
- option_create "app/views/#{plural_name}/show.json.jbuilder",
19
- "json.partial! '#{plural_name}/#{resource_name}.json', #{resource_name}: @#{resource_name}",
18
+ option_create "app/views/#{module_path}#{plural_name}/show.json.jbuilder",
19
+ "json.partial! '#{module_path}#{plural_name}/#{resource_name}.json', #{resource_name}: @#{resource_name}",
20
20
  "index jbuilder"
21
21
  end
22
22
  def generate_models
23
- option_create "app/views/#{plural_name}/_#{plural_name}.json.jbuilder",
24
- "json.array! #{plural_name}, partial: '#{plural_name}/#{resource_name}.json', as: :#{resource_name}",
23
+ option_create "app/views/#{module_path}#{plural_name}/_#{plural_name}.json.jbuilder",
24
+ "json.array! #{plural_name}, partial: '#{module_path}#{plural_name}/#{resource_name}.json', as: :#{resource_name}",
25
25
  "models jbuilder"
26
26
  end
27
27
  def generate_model
28
- option_create "app/views/#{plural_name}/_#{resource_name}.json.jbuilder",
28
+ option_create "app/views/#{module_path}#{plural_name}/_#{resource_name}.json.jbuilder",
29
29
  "json.extract! #{resource_name} #{attributes_string}",
30
30
  "model jbuilder"
31
31
  end
@@ -4,20 +4,21 @@ module NgOnRails
4
4
  desc "Creates NgOnRails-style AngularJS layout"
5
5
 
6
6
  # arguments
7
+ argument :full_model_name, type: :string, required: false, desc: "model name"
7
8
  class_option :app_controller, type: :boolean, required: false, default: true, desc: "create app_controller"
8
9
  class_option :build, type: :boolean, required: false, default: true, desc: "BUILD as ng_data default"
9
10
  class_option :layout_name, type: :string, required: false, default: "application", desc: "name of layout. defaults to 'application', creating the file application.html.<format>"
10
11
 
11
12
  def copy_layout
12
13
  option_template "#{LayoutGenerator.source_root}/#{options[:format]}/layout_template.html.#{options[:format]}.erb",
13
- "app/views/layouts/#{options[:layout_name]}.html.#{options[:format]}",
14
+ "app/views/layouts/#{module_path}#{options[:layout_name]}.html.#{options[:format]}",
14
15
  "layout file"
15
16
  end
16
17
 
17
18
  def copy_app_controller
18
19
  if options[:app_controller]
19
20
  option_copy_file "#{LayoutGenerator.source_root}/app_controller_template.js.coffee",
20
- "app/assets/javascripts/angular_app/controllers/app_controller.js.coffee",
21
+ "app/assets/javascripts/#{module_path}angular_app/controllers/app_controller.js.coffee",
21
22
  "app controller"
22
23
  end
23
24
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails/generators'
2
+ require "ng_on_rails/config_manager"
2
3
  module NgOnRails
3
4
  class NgOnRailsGenerator < Rails::Generators::Base
4
5
  desc "Shared options and methods for NgOnRails Generators"
@@ -16,10 +17,36 @@ module NgOnRails
16
17
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
17
18
  end
18
19
 
20
+ def set_attributes
21
+ if (defined?(full_model_name) && !full_model_name.nil?)
22
+ if full_model_name.include?("::")
23
+ parts = full_model_name.split("::")
24
+ @module_name = parts[0]
25
+ @model_name = parts[1]
26
+ else
27
+ @model_name = full_model_name
28
+ end
29
+ end
30
+ end
31
+
19
32
  private
20
33
 
34
+ def module_name
35
+ return @module_name
36
+ end
37
+
38
+ def module_path
39
+ unless module_name.nil?
40
+ "#{module_name.underscore}/"
41
+ end
42
+ end
43
+
44
+ def model_name
45
+ @model_name
46
+ end
47
+
21
48
  def class_name
22
- @class_name ||= model_name.classify
49
+ @class_name ||= @model_name.classify
23
50
  end
24
51
 
25
52
  def resource_name
@@ -30,12 +57,27 @@ module NgOnRails
30
57
  @plural_name ||= resource_name.pluralize
31
58
  end
32
59
 
60
+ #
61
+ # Config
62
+ #
63
+
64
+ def config
65
+ @config ||= ConfigManager.load_config
66
+ end
67
+
68
+ def mounted_path
69
+ if @mounted_path.nil? && !config['mounted_path'].blank?
70
+ @mounted_path = "#{config['mounted_path']}/"
71
+ end
72
+ @mounted_path
73
+ end
74
+
33
75
  #
34
76
  # View Helpers
35
77
  #
36
78
 
37
79
  def path_to_index_page
38
- Rails.application.routes.url_helpers.send("#{plural_name}_path")
80
+ "/#{mounted_path}#{plural_name}"
39
81
  end
40
82
 
41
83
  def belongs_to_array
@@ -2,15 +2,12 @@ require File.join(File.dirname(__FILE__), 'ng_on_rails_generator')
2
2
  module NgOnRails
3
3
  class ResourceGenerator < NgOnRails::NgOnRailsGenerator
4
4
  desc "Creates NgOnRails-style AngularJS Resource Service"
5
- argument :model_name, type: :string, required: true, desc: "model name"
5
+ argument :full_model_name, type: :string, required: true, desc: "model name"
6
6
 
7
7
  def generate_layout
8
8
  option_template "#{ResourceGenerator.source_root}/resource_template.js.erb",
9
- "app/assets/javascripts/angular_app/services/#{resource_name}.js.coffee",
9
+ "app/assets/javascripts/#{module_path}angular_app/services/#{resource_name}.js.coffee",
10
10
  "#{resource_name} resource"
11
11
  end
12
-
13
- private
14
-
15
12
  end
16
13
  end
@@ -3,7 +3,7 @@ module NgOnRails
3
3
  class ScaffoldGenerator < NgOnRails::NgOnRailsGenerator
4
4
  desc "Creates NgOnRails-style AngularJS Views"
5
5
 
6
- argument :model_name, type: :string, required: true, desc: "required"
6
+ argument :full_model_name, type: :string, required: true, desc: "required"
7
7
  class_option :layout, type: :boolean, required: false, default: true, desc: "create layout"
8
8
  # layout generator
9
9
  class_option :app_controller, type: :boolean, required: false, default: true, desc: "create app_controller"
@@ -14,17 +14,17 @@ module NgOnRails
14
14
 
15
15
  def generate_layout
16
16
  if options[:layout]
17
- generate "ng_on_rails:layout #{options_string}"
17
+ generate "ng_on_rails:layout #{full_model_name} #{options_string}"
18
18
  end
19
19
  end
20
20
  def generate_resource
21
- generate "ng_on_rails:resource #{model_name} #{options_string}"
21
+ generate "ng_on_rails:resource #{full_model_name} #{options_string}"
22
22
  end
23
23
  def generate_controller
24
- generate "ng_on_rails:controller #{model_name} #{options_string}"
24
+ generate "ng_on_rails:controller #{full_model_name} #{options_string}"
25
25
  end
26
26
  def generate_views
27
- generate "ng_on_rails:views #{model_name} #{options_string}"
27
+ generate "ng_on_rails:views #{full_model_name} #{options_string}"
28
28
  end
29
29
 
30
30
  private
@@ -36,8 +36,8 @@ NgOnRailsApp.controller '<%="#{class_name.pluralize}"%>Controller', [
36
36
  ctrl.data.active<%="#{class_name}"%> = {}
37
37
  ctrl.data.creating_new_<%="#{resource_name}"%> = true
38
38
  <%
39
- belongs_to_parameter_array.each do |relationship|
40
- %>ctrl.data.active<%="#{class_name}"%>.<%= relationship%> = <%= relationship %>
39
+ belongs_to_parameter_array.each do |owner|
40
+ %>ctrl.data.active<%="#{class_name}"%>.<%= owner %> = <%= owner %>
41
41
  <%
42
42
  end
43
43
  %>
@@ -66,8 +66,8 @@ NgOnRailsApp.controller '<%="#{class_name.pluralize}"%>Controller', [
66
66
  ctrl.data.editing_<%="#{resource_name}"%> = true
67
67
  <%="#{resource_name}"%>.is_displayed = false
68
68
  <%
69
- belongs_to_array.each do |relationship|
70
- %>ctrl.data.active<%="#{class_name}"%>.<%= relationship%> = <%= relationship %>
69
+ belongs_to_parameter_array.each do |owner|
70
+ %>ctrl.data.active<%="#{class_name}"%>.<%= owner %> = <%= owner %>
71
71
  <%
72
72
  end
73
73
  %>
@@ -1,5 +1,5 @@
1
1
  NgOnRailsApp.factory '<%="#{class_name}"%>', ($resource) ->
2
- <%="#{class_name}"%>Resource = $resource '/<%="#{plural_name}"%>/:id.json', {id: '@id'}, {
2
+ <%="#{class_name}"%>Resource = $resource '/<%= mounted_path %><%= plural_name %>/:id.json', {id: '@id'}, {
3
3
  update:{method: "PUT"}
4
4
  }
5
5
  class <%="#{class_name}"%> extends <%="#{class_name}"%>Resource
@@ -14,7 +14,7 @@ html
14
14
  head
15
15
  title NgOnRails | TestApp
16
16
  = csrf_meta_tags
17
- = stylesheet_link_tag "application", :media => "all"
17
+ = stylesheet_link_tag "<%= module_path %>application", :media => "all"
18
18
  == yield :meta
19
19
  == yield :styles
20
20
 
@@ -23,7 +23,7 @@ html
23
23
  == yield
24
24
 
25
25
  / scripts
26
- = javascript_include_tag "application"
26
+ = javascript_include_tag "<%= module_path %>application"
27
27
  script
28
28
  = render( partial: 'angular_app/rails_service', formats: ['js'], locals: { ng_data: ng_data} )
29
29
  == yield :javascripts
@@ -6,7 +6,7 @@
6
6
  @name_rep ||= property_hash[:name]
7
7
  if property_hash[:link]
8
8
  %>.td.<%= property_hash[:name] %><%= type_to_class(property_hash[:type]) %>
9
- a href="/<%= plural_name %>/{{<%= resource_name %>.id}}"
9
+ a href="/<%= mounted_path %><%= plural_name %>/{{<%= resource_name %>.id}}"
10
10
  span ng-bind="<%= resource_name %>.<%= property_hash[:name] %>"
11
11
  <%
12
12
  else
@@ -4,24 +4,24 @@ module NgOnRails
4
4
  desc "Creates NgOnRails-style AngularJS Views"
5
5
 
6
6
  # arguments
7
- argument :model_name, type: :string, required: true, desc: "required"
7
+ argument :full_model_name, type: :string, required: true, desc: "required"
8
8
  class_option :styles, type: :boolean, required: false, default: true, desc: "add ng_on_rails_styles.css"
9
9
 
10
10
  def generate_views
11
11
  option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/index.html.erb",
12
- "app/views/angular_app/#{plural_name}/index.html.#{options[:format]}",
12
+ "app/views/#{module_path}angular_app/#{plural_name}/index.html.#{options[:format]}",
13
13
  "index view"
14
14
  option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/show.html.erb",
15
- "app/views/angular_app/#{plural_name}/show.html.#{options[:format]}",
15
+ "app/views/#{module_path}angular_app/#{plural_name}/show.html.#{options[:format]}",
16
16
  "show view"
17
17
  option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_show.html.erb",
18
- "app/views/angular_app/#{plural_name}/_show.html.#{options[:format]}",
18
+ "app/views/#{module_path}angular_app/#{plural_name}/_show.html.#{options[:format]}",
19
19
  "_show partial"
20
20
  option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_form.html.erb",
21
- "app/views/angular_app/#{plural_name}/_form.html.#{options[:format]}",
21
+ "app/views/#{module_path}angular_app/#{plural_name}/_form.html.#{options[:format]}",
22
22
  "_form partial"
23
23
  option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_model.html.erb",
24
- "app/views/angular_app/#{plural_name}/_#{resource_name}.html.#{options[:format]}",
24
+ "app/views/#{module_path}angular_app/#{plural_name}/_#{resource_name}.html.#{options[:format]}",
25
25
  "_#{resource_name} partial"
26
26
  end
27
27
 
@@ -62,7 +62,7 @@ module NgOnRails
62
62
 
63
63
  def generate_jbuilder_files
64
64
  if options[:jbuilder] || options[:rails_views]
65
- generate "ng_on_rails:jbuilder #{class_name} #{jbuilder_attributes} --overwrite=#{options[:overwrite]}"
65
+ generate "ng_on_rails:jbuilder #{full_model_name} #{jbuilder_attributes} --overwrite=#{options[:overwrite]}"
66
66
  end
67
67
  end
68
68
 
@@ -142,11 +142,11 @@ module NgOnRails
142
142
  #
143
143
 
144
144
  def index_path
145
- @index_path ||= "app/views/#{plural_name}/index.html.#{options[:format]}"
145
+ @index_path ||= "app/views/#{module_path}#{plural_name}/index.html.#{options[:format]}"
146
146
  end
147
147
 
148
148
  def show_path
149
- @show_path ||= "app/views/#{plural_name}/show.html.#{options[:format]}"
149
+ @show_path ||= "app/views/#{module_path}#{plural_name}/show.html.#{options[:format]}"
150
150
  end
151
151
 
152
152
  def jbuilder_attributes
data/lib/ng_on_rails.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  require "ng_on_rails/engine"
2
2
  module NgOnRails
3
- end
3
+ mattr_accessor :config, :engine_path
4
+
5
+ def self.set_engine engine
6
+ self.engine_path = "#{engine.name.underscore}/"
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ module ConfigManager
2
+ @@config = nil
3
+
4
+ def self.load_config
5
+ config_path = "config/ng_on_rails.yml"
6
+ config = self.load_yaml(config_path)
7
+ unless config.blank? || config['test_app_path'].blank?
8
+ config_path = "#{config['test_app_path']}/config/ng_on_rails.yml"
9
+ config = self.load_yaml(config_path)
10
+ end
11
+ config = YAML.load("empty: true") if config.blank?
12
+ config
13
+ end
14
+
15
+ def self.load_yaml path
16
+ unless path.blank?
17
+ unless Rails.root.blank?
18
+ path = File.join(Rails.root.to_s,path)
19
+ end
20
+ if File.exists?(path)
21
+ YAML.load(File.read(path))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,9 +1,12 @@
1
+ require "ng_on_rails/config_manager"
2
+
1
3
  require 'angularjs-rails'
2
4
  require 'angular_rails_csrf'
3
5
 
4
6
  module NgOnRails
5
- class Engine < ::Rails::Engine
7
+ class Engine < ::Rails::Engine
6
8
  initializer 'ng_on_rails.load_static_assets' do |app|
9
+ NgOnRails.config = ConfigManager.load_config
7
10
  app.middleware.use ::ActionDispatch::Static, "#{root}/app"
8
11
  end
9
12
 
@@ -1,3 +1,3 @@
1
1
  module NgOnRails
2
- VERSION = "0.0.3.5"
2
+ VERSION = "0.0.3.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ng_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.5
4
+ version: 0.0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brookie Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: angularjs-rails
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.22
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.22
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: angular_rails_csrf
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.2
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.2
40
+ version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ files:
115
115
  - lib/generators/ng_on_rails/templates/views/slim/show.html.erb
116
116
  - lib/generators/ng_on_rails/views_generator.rb
117
117
  - lib/ng_on_rails.rb
118
+ - lib/ng_on_rails/config_manager.rb
118
119
  - lib/ng_on_rails/engine.rb
119
120
  - lib/ng_on_rails/version.rb
120
121
  - lib/tasks/ng_on_rails_tasks.rake