motorhead 0.2.0 → 0.3.0

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: cf3ab034b43dbc253be1de3a52bd36888ab9d330
4
- data.tar.gz: 84414b462e0b69d805cf8f54b569fc11f99e3107
3
+ metadata.gz: 246da5136e75d7169d3ec087b9eae348b6bee1c5
4
+ data.tar.gz: b2ba78b7defc6ad3cfee28339cab1a054279c59d
5
5
  SHA512:
6
- metadata.gz: 64a8d3b384a52eb0ef859c5a6f02b9386c6efde194d1d4c59ae0241d50815d45b341b675c43378be929ee12aaec0e901a8d81c001af03b4376930d8fe70f52b6
7
- data.tar.gz: d26b8028e083213581fbe434f1cf003b5f5fa98caf3863816ad300ae294575e911475455bf4043db32d95d73024be6c2ac9883cd79eb65d46f58f5457795252b
6
+ metadata.gz: 933ed54450abf427c2bc8a11b12586b930f399eb395eec12562224a1ecbadd1dcbdfe7aa3107c54ebe6138abaa438a16b0663886ec80850cdb3f75bbc6f93d56
7
+ data.tar.gz: 1bdf2fb57cdde93a48fa81e22d0bc160256217dc7a8eaa08597eb60405b8e47aa1f8310179b745f5a316a0c501c0e7039d998f66112d36e0dd68760ed2280930
data/README.md CHANGED
@@ -106,6 +106,22 @@ module MyAwesomeNewFeature
106
106
  end
107
107
  ```
108
108
 
109
+ You can configure a path to mount the Engine via `mount_at` directive. This value is defaulted to "/", which means the Engine routes will be mixed into the main app's routes.
110
+
111
+ Example:
112
+
113
+ ```ruby
114
+ # app/engines/my_awesome_new_feature/config/routes.rb
115
+ module MyAwesomeNewFeature
116
+ class Engine < ::Rails::Engine
117
+ include Motorhead::Engine
118
+
119
+ # all routes inside this Engine will be prefixed by "/harley"
120
+ mount_at 'harley'
121
+ end
122
+ end
123
+ ```
124
+
109
125
  ### routes.rb
110
126
 
111
127
  All routes in engines' routes.rb will be automatically prepended to the main app's Routes.
@@ -189,6 +205,29 @@ Example:
189
205
  This generates a motorhead Engine in ~/app/engines/my\_awesome\_new\_feature/ directory. Plus, a controller that extends WelcomeController and implements index action inside the Engine.
190
206
 
191
207
 
208
+ ## Managing Engines
209
+
210
+ Motorhead includes a tiny admin console Engine call "RoadCrew" through which you can easily enable/disable each mounted Engine.
211
+ To use this, require `'motorhead/road_crew'` when bundling motorhead gem in your Gemfile:
212
+
213
+ ```ruby
214
+ # Gemfile
215
+ gem 'motorhead', path: '~/src/motorhead', require: ['motorhead', 'motorhead/road_crew']
216
+ ```
217
+
218
+ then render the `road_crew/button` Engine partial to put a button inside somewhere in your view (usually in the header or footer?):
219
+
220
+ ```erb
221
+ # app/views/layouts/application.html.erb
222
+ <%= render engine: 'road_crew/button' %>
223
+ ```
224
+
225
+ You might also want to configure the RoadCrew Engine's `active_if` directive for security.
226
+
227
+ ```ruby
228
+ # config/initializers/mh_road_crew.rb
229
+ RoadCrew::Engine.active_if { current_user.admin? }
230
+ ```
192
231
 
193
232
 
194
233
 
@@ -10,3 +10,4 @@ gem 'routes_fallback', path: '../test/dummy_app/app/engines/routes_fallback'
10
10
  gem 'italian', path: '../test/dummy_app/app/engines/italian'
11
11
  gem 'spanish', path: '../test/dummy_app/app/engines/spanish'
12
12
  gem 'simple_controller', path: '../test/dummy_app/app/engines/simple_controller'
13
+ gem 'mount_at_capricorn', path: '../test/dummy_app/app/engines/mount_at_capricorn'
@@ -4,12 +4,13 @@ ActionView::Base.class_eval do
4
4
  if (Hash === options) && options.key?(:engine)
5
5
  ext_name = options[:engine][/[^\/]*/]
6
6
  if ext_name.classify.constantize::Engine.active? controller
7
- return view_renderer.render(self, options, &block)
8
- else
9
- return capture(&block)
7
+ view_renderer.render(self, options, &block)
8
+ elsif block
9
+ capture(&block)
10
10
  end
11
+ else
12
+ render_without_motorhead options, locals, &block
11
13
  end
12
- render_without_motorhead options, locals, &block
13
14
  end
14
15
 
15
16
  alias_method_chain :render, :motorhead
@@ -3,7 +3,7 @@ module Motorhead
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- attr_accessor :on_error
6
+ attr_accessor :on_error, :mount_at
7
7
 
8
8
  def active_if(&block)
9
9
  @active_if = block
@@ -12,6 +12,10 @@ module Motorhead
12
12
  def active?(controller)
13
13
  controller.instance_eval(&@active_if)
14
14
  end
15
+
16
+ def mount_at(path = nil)
17
+ path ? @mount_at = path : @mount_at
18
+ end
15
19
  end
16
20
 
17
21
  included do
@@ -20,7 +24,7 @@ module Motorhead
20
24
  engine_kls = self
21
25
  ActiveSupport.on_load :after_initialize do
22
26
  Rails.application.routes.prepend do
23
- mount engine_kls, at: '/'
27
+ mount engine_kls, at: engine_kls.mount_at || '/'
24
28
  end
25
29
  end
26
30
  end
@@ -0,0 +1 @@
1
+ require 'motorhead/road_crew/lib/road_crew'
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
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
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the road_crew/engine_settings controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,18 @@
1
+ class RoadCrew::EngineSettingsController < ActionController::Base
2
+ include Motorhead::Controller
3
+ layout false
4
+
5
+ def index
6
+ @engine_settings = JSON.parse(cookies['road_crew_engine_settings'].presence || '{}')
7
+ all_engine_names = Rails::Engine.subclasses.select {|e| e < Motorhead::Engine}.map {|e| e.parent.name} - ['RoadCrew']
8
+ # enable by default
9
+ (all_engine_names - @engine_settings.keys).each {|engine_name| @engine_settings[engine_name] = '1'}
10
+ end
11
+
12
+ def update_all
13
+ # on, off = engines.partition {|k, v| v == '1'}.map {|a| a.map {|kv| kv.first}}
14
+ engine_settings = JSON.parse(cookies['road_crew_engine_settings'].presence || '{}').merge params[:engine_setting]
15
+ cookies['road_crew_engine_settings'] = engine_settings.to_json
16
+ redirect_to request.referer
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ <%= link_to '㊙️', road_crew.engine_settings_path, id: 'road_crew_button', class: 'closed', remote: true %>
2
+ <div id="road_crew_container" style="position:fixed; bottom: 0px; right: 0px"></div>
3
+ <script type="text/javascript">
4
+ (function() {
5
+ $(function() {
6
+ $("#road_crew_button").on("ajax:success", function(e, data, status, xhr) {
7
+ $("#road_crew_container").html(xhr.responseText);
8
+ })
9
+ });
10
+ }).call(this);
11
+ </script>
@@ -0,0 +1,26 @@
1
+ <div style="background-color: #fbbaaf; border: 1px solid #000; border-radius: 7px; padding: 2px;">
2
+ <div style="text-align: right;"><%= link_to '×', 'javascript: void(0);', id: 'road_crew_close' %></div>
3
+ <% if @engine_settings.any? %>
4
+ <strong>Engines List</strong><br>
5
+ <%= form_for road_crew.engine_settings_path, method: :put do %>
6
+ <% @engine_settings.each do |name, enabled| %>
7
+ <p>
8
+ <%= hidden_field_tag "engine_setting[#{name}]", '0' %><%= check_box_tag "engine_setting[#{name}]", '1', enabled == '1' %>
9
+ <label for="<%= "engine_setting_#{name}" %>"><%= name %></label>
10
+ </p>
11
+ <% end %>
12
+ <div style="text-align: center;"><%= submit_tag 'Save' %></div>
13
+ <% end %>
14
+ <% else %>
15
+ No Motorhead Engine found.
16
+ <% end %>
17
+ </div>
18
+ <script type="text/javascript">
19
+ (function() {
20
+ $(function() {
21
+ $("#road_crew_close").on("click", function(e) {
22
+ $("#road_crew_container").empty();
23
+ })
24
+ });
25
+ }).call(this);
26
+ </script>
@@ -0,0 +1,4 @@
1
+ RoadCrew::Engine.routes.draw do
2
+ resources :engine_settings, only: :index
3
+ put 'engine_settings' => 'engine_settings#update_all'
4
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'road_crew/engine'
2
+ $LOAD_PATH.unshift __dir__
@@ -0,0 +1,20 @@
1
+ require 'motorhead/engine'
2
+
3
+ module RoadCrew
4
+ class Engine < ::Rails::Engine
5
+ include Motorhead::Engine
6
+
7
+ active_if { true }
8
+ mount_at 'motorhead/road_crew'
9
+
10
+ Motorhead::Engine::ClassMethods.class_eval do
11
+ # overwrite active? to check cookie value as well
12
+ def active?(controller)
13
+ if (settings = controller.send(:cookies)['road_crew_engine_settings'])
14
+ return false if JSON.parse(settings)[controller.class.parent.name] == '0'
15
+ end
16
+ controller.instance_eval(&@active_if)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Describe your gem and declare its dependencies:
4
+ Gem::Specification.new do |s|
5
+ s.name = "road_crew"
6
+ s.version = '0'
7
+ s.authors = [""]
8
+ s.email = [""]
9
+ s.homepage = ""
10
+ s.summary = ""
11
+ s.description = ""
12
+ s.license = "MIT"
13
+
14
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
15
+
16
+ s.add_dependency "rails", "~> 4.2.4"
17
+
18
+ s.add_development_dependency "sqlite3"
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Motorhead
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motorhead
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,18 @@ files:
132
132
  - lib/motorhead/action_view.rb
133
133
  - lib/motorhead/config.rb
134
134
  - lib/motorhead/engine.rb
135
+ - lib/motorhead/road_crew.rb
136
+ - lib/motorhead/road_crew/app/assets/javascripts/road_crew/application.js
137
+ - lib/motorhead/road_crew/app/assets/javascripts/road_crew/engine_settings.js
138
+ - lib/motorhead/road_crew/app/assets/stylesheets/road_crew/application.css
139
+ - lib/motorhead/road_crew/app/assets/stylesheets/road_crew/engine_settings.scss
140
+ - lib/motorhead/road_crew/app/controllers/road_crew/engine_settings_controller.rb
141
+ - lib/motorhead/road_crew/app/views/road_crew/_button.html.erb
142
+ - lib/motorhead/road_crew/app/views/road_crew/engine_settings/index.html.erb
143
+ - lib/motorhead/road_crew/config/routes.rb
144
+ - lib/motorhead/road_crew/lib/road_crew.rb
145
+ - lib/motorhead/road_crew/lib/road_crew/engine.rb
146
+ - lib/motorhead/road_crew/road_crew.gemspec
135
147
  - lib/motorhead/version.rb
136
148
  - motorhead.gemspec
137
149
  homepage: https://github.com/amatsuda/motorhead