chili 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile +1 -0
- data/README.md +15 -15
- data/lib/chili/engine.rb +4 -0
- data/lib/chili/version.rb +1 -1
- data/lib/generators/chili/USAGE +2 -2
- data/lib/generators/chili/extension_generator.rb +109 -0
- data/spec/dummy/{template_ext → blank_extension}/MIT-LICENSE +0 -0
- data/spec/dummy/blank_extension/README.rdoc +3 -0
- data/spec/dummy/{example/vendor/chili/social_ext/app/assets/images/social_ext → blank_extension/app/assets/images/blank_extension}/.gitkeep +0 -0
- data/spec/dummy/{template_ext/app/assets/javascripts/template_ext → blank_extension/app/assets/javascripts/blank_extension}/application.js +0 -0
- data/spec/dummy/{template_ext/app/assets/stylesheets/template_ext → blank_extension/app/assets/stylesheets/blank_extension}/application.css +0 -0
- data/spec/dummy/blank_extension/app/overrides/layouts/application/assets.html.erb.deface +3 -0
- data/spec/dummy/{template_ext → blank_extension}/app/overrides/layouts/application/example.html.erb.deface +2 -2
- data/spec/dummy/{template_ext/template_ext.gemspec → blank_extension/blank_extension.gemspec} +7 -7
- data/spec/dummy/blank_extension/config/routes.rb +3 -0
- data/spec/dummy/{template_ext/lib/template_ext.rb → blank_extension/lib/blank_extension.rb} +2 -2
- data/spec/dummy/{example/vendor/chili/social_ext/lib/social_ext → blank_extension/lib/blank_extension}/engine.rb +2 -2
- data/spec/dummy/{template_ext/lib/template_ext → blank_extension/lib/blank_extension}/version.rb +1 -1
- data/spec/dummy/{template_ext/lib/tasks/template_ext_tasks.rake → blank_extension/lib/tasks/blank_extension_tasks.rake} +1 -1
- data/spec/dummy/{template_ext → blank_extension}/script/rails +1 -1
- data/spec/dummy/example/config/application.rb +2 -1
- data/spec/dummy/example/config/boot.rb +2 -1
- data/spec/dummy/example/db/migrate/20120513032032_create_social_extension_likes.rb +11 -0
- data/spec/dummy/example/db/schema.rb +1 -1
- data/spec/dummy/example/vendor/chili/invites_extension/.gitignore +3 -0
- data/spec/dummy/{template_ext/app/assets/images/template_ext → example/vendor/chili/invites_extension/app/assets/images/invites_extension}/.gitkeep +0 -0
- data/spec/dummy/example/vendor/chili/invites_extension/app/assets/javascripts/invites_extension/application.js +13 -0
- data/spec/dummy/example/vendor/chili/invites_extension/app/assets/stylesheets/invites_extension/application.css +13 -0
- data/spec/dummy/example/vendor/chili/invites_extension/app/overrides/posts/index/disclaimer.html.erb.deface +2 -0
- data/spec/dummy/example/vendor/chili/invites_extension/config/routes.rb +3 -0
- data/spec/dummy/example/vendor/chili/invites_extension/lib/invites_extension.rb +7 -0
- data/spec/dummy/example/vendor/chili/invites_extension/lib/invites_extension/engine.rb +10 -0
- data/spec/dummy/example/vendor/chili/social_extension/app/assets/images/social_extension/.gitkeep +0 -0
- data/spec/dummy/example/vendor/chili/{social_ext/app/assets/javascripts/social_ext → social_extension/app/assets/javascripts/social_extension}/application.js +0 -0
- data/spec/dummy/example/vendor/chili/{social_ext/app/assets/stylesheets/social_ext → social_extension/app/assets/stylesheets/social_extension}/application.css.scss +0 -0
- data/spec/dummy/example/vendor/chili/social_extension/app/controllers/social_extension/likes_controller.rb +20 -0
- data/spec/dummy/example/vendor/chili/{social_ext/app/models/social_ext → social_extension/app/models/social_extension}/like.rb +1 -1
- data/spec/dummy/example/vendor/chili/{social_ext/app/models/social_ext → social_extension/app/models/social_extension}/post.rb +1 -1
- data/spec/dummy/example/vendor/chili/{social_ext/app/models/social_ext → social_extension/app/models/social_extension}/user.rb +1 -1
- data/spec/dummy/example/vendor/chili/{social_ext → social_extension}/app/overrides/posts/_post/like_actions.html.erb.deface +2 -2
- data/spec/dummy/example/vendor/chili/{social_ext → social_extension}/app/overrides/posts/index/disclaimer.html.erb.deface +0 -0
- data/spec/dummy/example/vendor/chili/social_extension/app/overrides/posts/index/like_links.html.erb.deface +2 -0
- data/spec/dummy/example/vendor/chili/{social_ext/app/views/social_ext → social_extension/app/views/social_extension}/likes/index.html.erb +0 -0
- data/spec/dummy/example/vendor/chili/social_extension/config/routes.rb +4 -0
- data/spec/dummy/example/vendor/chili/social_extension/db/migrate/20120513031021_create_likes_extension_likes.rb +10 -0
- data/spec/dummy/example/vendor/chili/{social_ext/lib/social_ext.rb → social_extension/lib/social_extension.rb} +2 -2
- data/spec/dummy/{template_ext/lib/template_ext → example/vendor/chili/social_extension/lib/social_extension}/engine.rb +2 -2
- data/spec/generators/chili/chili_generator_spec.rb +4 -4
- data/spec/requests/{social_ext_spec.rb → social_extension_spec.rb} +11 -2
- metadata +133 -86
- data/lib/generators/chili/chili_generator.rb +0 -104
- data/spec/dummy/example/db/migrate/20120513032032_create_social_ext_likes.rb +0 -11
- data/spec/dummy/example/vendor/chili/social_ext/app/controllers/social_ext/likes_controller.rb +0 -14
- data/spec/dummy/example/vendor/chili/social_ext/app/overrides/layouts/application/assets.html.erb.deface +0 -2
- data/spec/dummy/example/vendor/chili/social_ext/app/overrides/posts/index/like_links.html.erb.deface +0 -2
- data/spec/dummy/example/vendor/chili/social_ext/config/routes.rb +0 -4
- data/spec/dummy/example/vendor/chili/social_ext/db/migrate/20120513031021_create_likes_ext_likes.rb +0 -10
- data/spec/dummy/example/vendor/chili/social_ext/db/migrate/20120513031021_create_social_ext_likes.rb +0 -10
- data/spec/dummy/template_ext/README.rdoc +0 -3
- data/spec/dummy/template_ext/app/overrides/layouts/application/assets.html.erb.deface +0 -3
- data/spec/dummy/template_ext/config/routes.rb +0 -3
data/.gitignore
CHANGED
@@ -16,7 +16,7 @@ spec/dummy/example/db/*.sqlite3
|
|
16
16
|
spec/dummy/example/log/*.log
|
17
17
|
spec/dummy/example/tmp/
|
18
18
|
spec/dummy/example/.sass-cache
|
19
|
-
spec/dummy/example/vendor/chili/
|
19
|
+
spec/dummy/example/vendor/chili/blank_extension
|
20
20
|
spec/dummy/example/Gemfile
|
21
21
|
tmp
|
22
22
|
.DS_Store
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,11 +26,11 @@ Chili extensions are like mini apps that are created inside your main app's vend
|
|
26
26
|
As an example, assuming you want to add a new extension named "social" that exposes a new feature in the form of a like-button
|
27
27
|
to a subset of users, first within your main app run:
|
28
28
|
|
29
|
-
$ rails g chili social
|
29
|
+
$ rails g chili:extension social
|
30
30
|
|
31
31
|
This is basically a shortcut for running the `rails plugin new` engine generator with a custom template and will:
|
32
32
|
|
33
|
-
1. Create a the directory `vendor/chili/
|
33
|
+
1. Create a the directory `vendor/chili/social_extension` containing the basic structure for the extension
|
34
34
|
2. Add a reference to the extension to the main app gemfile
|
35
35
|
|
36
36
|
Since the extension is mounted as a gem you'll have to run `bundle`
|
@@ -38,12 +38,12 @@ after this to start using the extension.
|
|
38
38
|
|
39
39
|
### Define who can see the extension
|
40
40
|
|
41
|
-
Use the active_if block to control whether new
|
41
|
+
Use the active_if block to control whether new the extension is visible or not.
|
42
42
|
The context of the active_if block is the application controller so you can use any methods available to that.
|
43
43
|
|
44
44
|
```ruby
|
45
|
-
# lib/
|
46
|
-
module
|
45
|
+
# lib/social_extension.rb
|
46
|
+
module SocialExtension
|
47
47
|
extend Chili::Activatable
|
48
48
|
active_if { logged_in? && current_user.admin? } # Extension is only visible to logged in admin users
|
49
49
|
end
|
@@ -58,13 +58,13 @@ For example, assuming the main app has the partial `app/views/posts/_post.html.e
|
|
58
58
|
```erb
|
59
59
|
<% # app/overrides/posts/_post/like_button.html.erb.deface (folder should mirror main app view path) %>
|
60
60
|
<!-- insert_bottom 'tr' -->
|
61
|
-
<td><%= link_to 'Like!',
|
61
|
+
<td><%= link_to 'Like!', social_extension.likes_path(like: {post_id: post}), method: :post %></td>
|
62
62
|
```
|
63
63
|
|
64
64
|
### Adding new resources
|
65
65
|
|
66
66
|
Go to the extension's directory and use `rails g scaffold Like`. The new resource will be namespaced to SocialExt::Like
|
67
|
-
and automounted in the main app at `/chili/
|
67
|
+
and automounted in the main app at `/chili/social_extension/likes`, but only accessible when active_if is true.
|
68
68
|
All the rules for using [isolated engine models](http://railscasts.com/episodes/277-mountable-engines?view=asciicast) apply.
|
69
69
|
|
70
70
|
### Migrations
|
@@ -72,7 +72,7 @@ All the rules for using [isolated engine models](http://railscasts.com/episodes/
|
|
72
72
|
Migrations are handled the same way as engines. Use the
|
73
73
|
following commands after you've added a new migration to your extension:
|
74
74
|
|
75
|
-
$ rake
|
75
|
+
$ rake social_extension:migrations:install
|
76
76
|
$ rake db:migrate
|
77
77
|
|
78
78
|
### Modifying existing models
|
@@ -81,8 +81,8 @@ Create a model with the same name as the one you want to modify by running: `rai
|
|
81
81
|
and edit it to inherit from the original:
|
82
82
|
|
83
83
|
```ruby
|
84
|
-
# app/models/
|
85
|
-
module
|
84
|
+
# app/models/social_extension/user.rb
|
85
|
+
module SocialExtension
|
86
86
|
class User < ::User
|
87
87
|
has_many :likes
|
88
88
|
end
|
@@ -92,19 +92,19 @@ end
|
|
92
92
|
Access in your overrides/extension views through the namespaced model:
|
93
93
|
|
94
94
|
```erb
|
95
|
-
<%=
|
96
|
-
<%= current_user.becomes(
|
95
|
+
<%= SocialExtension::User.first.likes %>
|
96
|
+
<%= current_user.becomes(SocialExtension::User).likes %>
|
97
97
|
```
|
98
98
|
|
99
99
|
### Stylesheets/javascripts
|
100
100
|
|
101
|
-
Files added to the extension's `app/assets/
|
101
|
+
Files added to the extension's `app/assets/social_extension/javascripts|stylesheets` directory are automatically injected into the layout using a pre-generated override:
|
102
102
|
|
103
103
|
```erb
|
104
104
|
<% # app/overrides/layouts/application/assets.html.erb.deface %>
|
105
105
|
<!-- insert_bottom 'head' -->
|
106
|
-
<%= stylesheet_link_tag '
|
107
|
-
<%= javascript_include_tag '
|
106
|
+
<%= stylesheet_link_tag 'social_extension/application' %>
|
107
|
+
<%= javascript_include_tag 'social_extension/application' %>
|
108
108
|
```
|
109
109
|
|
110
110
|
If you don't need any css/js in your extension, you can remove this file.
|
data/lib/chili/engine.rb
CHANGED
data/lib/chili/version.rb
CHANGED
data/lib/generators/chili/USAGE
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
module Chili
|
2
|
+
module Generators
|
3
|
+
class ExtensionGenerator < Rails::Generators::NamedBase
|
4
|
+
NAME = "#{ARGV[0]}_extension"
|
5
|
+
PATH = "vendor/chili/#{NAME}"
|
6
|
+
|
7
|
+
def run_plugin_generator
|
8
|
+
ARGV[0] = PATH
|
9
|
+
ARGV[1] = "--mountable"
|
10
|
+
ARGV[2] = '--skip-test-unit'
|
11
|
+
ARGV[3] = '--skip-bundle'
|
12
|
+
|
13
|
+
require 'rails/generators'
|
14
|
+
require 'rails/generators/rails/plugin_new/plugin_new_generator'
|
15
|
+
Rails::Generators::PluginNewGenerator.start
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_destination_root
|
19
|
+
self.destination_root = ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit_gemspec
|
23
|
+
require File.expand_path('../../../chili/version', __FILE__)
|
24
|
+
gemspec = "#{NAME}.gemspec"
|
25
|
+
gsub_file gemspec, '# s.add_dependency "jquery-rails"', "s.add_dependency 'chili', '~> #{Chili::VERSION}'"
|
26
|
+
gsub_file gemspec, 'TODO: Your name', `git config user.NAME`.chomp
|
27
|
+
gsub_file gemspec, 'TODO: Your email', `git config user.email`.chomp
|
28
|
+
gsub_file gemspec, /TODO(:\s)?/, ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_gem_to_main_gemfile
|
32
|
+
append_to_file "../../../Gemfile", "gem '#{NAME}', path: '#{PATH}'"
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_unused_files
|
36
|
+
remove_dir "app/controllers/#{NAME}"
|
37
|
+
remove_dir "app/helpers/#{NAME}"
|
38
|
+
remove_dir 'app/views/layouts'
|
39
|
+
remove_file 'Gemfile'
|
40
|
+
remove_file 'Rakefile'
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_jquery_stuff
|
44
|
+
gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery_ujs\n", ''
|
45
|
+
gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery\n", ''
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_up_custom_generator
|
49
|
+
inject_into_file "lib/#{NAME}/engine.rb", after: "isolate_namespace #{NAME.camelcase}\n" do <<-RUBY
|
50
|
+
config.generators do |g|
|
51
|
+
g.scaffold_controller :chili
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_up_rspec
|
58
|
+
inject_into_file "lib/#{NAME}/engine.rb", :after => " g.scaffold_controller :chili\n" do <<-RUBY
|
59
|
+
g.test_framework :rspec, view_specs: false, routing_specs: false, controller_specs: false
|
60
|
+
g.integration_tool :rspec
|
61
|
+
RUBY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def clean_up_gitignore
|
66
|
+
gsub_file ".gitignore", /test\/dummy.*\n/, ''
|
67
|
+
end
|
68
|
+
|
69
|
+
def automount_engine
|
70
|
+
prepend_to_file 'config/routes.rb', "#{NAME.camelcase}::Engine.automount!\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
def include_chili_libs
|
74
|
+
prepend_to_file "lib/#{NAME}.rb", "require \"chili\"\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
def include_active_if
|
78
|
+
inject_into_file "lib/#{NAME}.rb", :after => "module #{NAME.camelcase}\n" do <<-RUBY
|
79
|
+
extend Chili::Activatable
|
80
|
+
active_if { logged_in? }
|
81
|
+
RUBY
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_dummy_override
|
86
|
+
example_file_path = "app/overrides/layouts/application/example.html.erb.deface"
|
87
|
+
create_file example_file_path do <<-RUBY
|
88
|
+
<!-- insert_bottom 'body' -->
|
89
|
+
<div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>
|
90
|
+
#{NAME} active - edit/remove this file:<br/>
|
91
|
+
<strong>#{PATH}/#{example_file_path}</strong><br/>
|
92
|
+
<%= link_to 'deface docs', 'https://github.com/railsdog/deface', target: '_blank' %>
|
93
|
+
</div>
|
94
|
+
RUBY
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_assets_override
|
99
|
+
create_file 'app/overrides/layouts/application/assets.html.erb.deface' do <<-RUBY
|
100
|
+
<!-- insert_bottom 'head' -->
|
101
|
+
<%= stylesheet_link_tag '#{NAME}/application' %>
|
102
|
+
<%= javascript_include_tag '#{NAME}/application' %>
|
103
|
+
RUBY
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<!-- insert_bottom 'body' -->
|
2
2
|
<div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>
|
3
|
-
|
4
|
-
<strong>vendor/chili/
|
3
|
+
blank_extension active - edit/remove this file:<br/>
|
4
|
+
<strong>vendor/chili/blank_extension/app/overrides/layouts/application/example.html.erb.deface</strong><br/>
|
5
5
|
<%= link_to 'deface docs', 'https://github.com/railsdog/deface', target: '_blank' %>
|
6
6
|
</div>
|
data/spec/dummy/{template_ext/template_ext.gemspec → blank_extension/blank_extension.gemspec}
RENAMED
@@ -1,22 +1,22 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
|
3
3
|
# Maintain your gem's version:
|
4
|
-
require "
|
4
|
+
require "blank_extension/version"
|
5
5
|
|
6
6
|
# Describe your gem and declare its dependencies:
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "
|
9
|
-
s.version =
|
8
|
+
s.name = "blank_extension"
|
9
|
+
s.version = BlankExtension::VERSION
|
10
10
|
s.authors = ["GIT_AUTHOR"]
|
11
11
|
s.email = ["GIT_EMAIL"]
|
12
12
|
s.homepage = ""
|
13
|
-
s.summary = "Summary of
|
14
|
-
s.description = "Description of
|
13
|
+
s.summary = "Summary of BlankExtension."
|
14
|
+
s.description = "Description of BlankExtension."
|
15
15
|
|
16
16
|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
17
17
|
|
18
|
-
s.add_dependency "rails", "~> 3.2.
|
19
|
-
s.add_dependency 'chili', '~> 0.3.
|
18
|
+
s.add_dependency "rails", "~> 3.2.8"
|
19
|
+
s.add_dependency 'chili', '~> 0.3.2'
|
20
20
|
|
21
21
|
s.add_development_dependency "sqlite3"
|
22
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module BlankExtension
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
isolate_namespace
|
3
|
+
isolate_namespace BlankExtension
|
4
4
|
config.generators do |g|
|
5
5
|
g.scaffold_controller :chili
|
6
6
|
g.test_framework :rspec, view_specs: false, routing_specs: false, controller_specs: false
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
3
|
|
4
4
|
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
-
ENGINE_PATH = File.expand_path('../../lib/
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/blank_extension/engine', __FILE__)
|
6
6
|
|
7
7
|
require 'rails/all'
|
8
8
|
require 'rails/engine/commands'
|
@@ -8,4 +8,5 @@ if File.exist?(gemfile)
|
|
8
8
|
end
|
9
9
|
|
10
10
|
$:.unshift File.expand_path('../../../../../lib', __FILE__)
|
11
|
-
$:.unshift File.expand_path('../../vendor/chili/
|
11
|
+
$:.unshift File.expand_path('../../vendor/chili/social_extension/lib', __FILE__)
|
12
|
+
$:.unshift File.expand_path('../../vendor/chili/invites_extension/lib', __FILE__)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This migration comes from social_extension (originally 20120513031021)
|
2
|
+
class CreateSocialExtensionLikes < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :social_extension_likes do |t|
|
5
|
+
t.integer :post_id
|
6
|
+
t.integer :user_id
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -19,7 +19,7 @@ ActiveRecord::Schema.define(:version => 20120513032032) do
|
|
19
19
|
t.datetime "updated_at", :null => false
|
20
20
|
end
|
21
21
|
|
22
|
-
create_table "
|
22
|
+
create_table "social_extension_likes", :force => true do |t|
|
23
23
|
t.integer "post_id"
|
24
24
|
t.integer "user_id"
|
25
25
|
t.datetime "created_at", :null => false
|
File without changes
|
@@ -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 vendor/assets/javascripts of plugins, if any, 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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
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 vendor/assets/stylesheets of plugins, if any, 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 top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|