chili 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ script: "rake app:db:setup && rake app:db:test:prepare && rake"
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Chili
1
+ # Chili [![Build Status](https://secure.travis-ci.org/balvig/chili.png?branch=master)](http://travis-ci.org/balvig/chili)
2
2
 
3
3
  Have you ever wanted to test out a new feature on only a subset of users?
4
4
  Did that implementation end up being lots of if/else statements embedded in the main code?
@@ -19,18 +19,18 @@ and run `bundle`.
19
19
 
20
20
  ## Usage
21
21
 
22
- Chili extensions are like mini apps that are created inside your main app's vendor directory using using the "chili" command.
22
+ Chili extensions are like mini apps that are created inside your main app's vendor directory using using the "chili" generator.
23
23
 
24
24
  ### Creating a new chili extension
25
25
 
26
26
  As an example, assuming you want to add a new extension named "social" that exposes a new social feature in the form of a like-button
27
- to a subset of users, first run within your main app:
27
+ to a subset of users, first within your main app run:
28
28
 
29
- $ chili new social
29
+ $ rails g chili 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_social containing the basic structure for the extension
33
+ 1. Create a the directory `vendor/chili_social` 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`
@@ -98,7 +98,7 @@ Access in your overrides/extension views through the namespaced model:
98
98
 
99
99
  ### Stylesheets/javascripts
100
100
 
101
- Files added to `app/assets/chili_social/javascripts|stylesheets` are automatically injected into the layout using a pre-generated override:
101
+ Files added to the extension's `app/assets/chili_social/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 %>
data/Rakefile CHANGED
@@ -6,8 +6,8 @@ rescue LoadError
6
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
7
  end
8
8
 
9
- # APP_RAKEFILE = File.expand_path("../spec/dummy/main_app/Rakefile", __FILE__)
10
- # load 'rails/tasks/engine.rake'
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/example/Rakefile", __FILE__)
10
+ load 'rails/tasks/engine.rake'
11
11
 
12
12
  require 'rspec/core/rake_task'
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Chili
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a new chili extension
3
+
4
+ Example:
5
+ rails generate chili social
6
+
7
+ This will create:
8
+ basic extension structure in vendor/chili_social
@@ -0,0 +1,104 @@
1
+ class ChiliGenerator < Rails::Generators::NamedBase
2
+ NAME = "chili_#{ARGV[0]}"
3
+ PATH = "vendor/#{NAME}"
4
+
5
+ def run_plugin_generator
6
+ ARGV[0] = PATH
7
+ ARGV[1] = "--mountable"
8
+ ARGV[2] = '--skip-test-unit'
9
+ ARGV[3] = '--skip-bundle'
10
+
11
+ require 'rails/generators'
12
+ require 'rails/generators/rails/plugin_new/plugin_new_generator'
13
+ Rails::Generators::PluginNewGenerator.start
14
+ end
15
+
16
+ def reset_destination_root
17
+ self.destination_root = ''
18
+ end
19
+
20
+ def edit_gemspec
21
+ require File.expand_path('../../../chili/version', __FILE__)
22
+ gemspec = "#{NAME}.gemspec"
23
+ gsub_file gemspec, '# s.add_dependency "jquery-rails"', "s.add_dependency 'chili', '~> #{Chili::VERSION}'"
24
+ gsub_file gemspec, 'TODO: Your name', `git config user.NAME`.chomp
25
+ gsub_file gemspec, 'TODO: Your email', `git config user.email`.chomp
26
+ gsub_file gemspec, /TODO(:\s)?/, ''
27
+ end
28
+
29
+ def add_gem_to_main_gemfile
30
+ append_to_file "../../Gemfile", "gem '#{NAME}', path: '#{PATH}'"
31
+ end
32
+
33
+ def remove_unused_files
34
+ remove_dir "app/controllers/#{NAME}"
35
+ remove_dir "app/helpers/#{NAME}"
36
+ remove_dir 'app/views/layouts'
37
+ remove_file 'Gemfile'
38
+ remove_file 'Rakefile'
39
+ end
40
+
41
+ def remove_jquery_stuff
42
+ gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery_ujs\n", ''
43
+ gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery\n", ''
44
+ end
45
+
46
+ def set_up_custom_generator
47
+ inject_into_file "lib/#{NAME}/engine.rb", after: "isolate_namespace #{NAME.camelcase}\n" do <<-RUBY
48
+ config.generators do |g|
49
+ g.scaffold_controller :chili
50
+ end
51
+ RUBY
52
+ end
53
+ end
54
+
55
+ def set_up_rspec
56
+ inject_into_file "lib/#{NAME}/engine.rb", :after => " g.scaffold_controller :chili\n" do <<-RUBY
57
+ g.test_framework :rspec, view_specs: false, routing_specs: false, controller_specs: false
58
+ g.integration_tool :rspec
59
+ RUBY
60
+ end
61
+ end
62
+
63
+ def clean_up_gitignore
64
+ gsub_file ".gitignore", /test\/dummy.*\n/, ''
65
+ end
66
+
67
+ def automount_engine
68
+ prepend_to_file 'config/routes.rb', "#{NAME.camelcase}::Engine.automount!\n"
69
+ end
70
+
71
+ def include_chili_libs
72
+ prepend_to_file "lib/#{NAME}.rb", "require \"chili\"\n"
73
+ end
74
+
75
+ def include_active_if
76
+ inject_into_file "lib/#{NAME}.rb", :after => "module #{NAME.camelcase}\n" do <<-RUBY
77
+ extend Chili::Activatable
78
+ active_if { logged_in? }
79
+ RUBY
80
+ end
81
+ end
82
+
83
+ def add_dummy_override
84
+ example_file_path = "app/overrides/layouts/application/example.html.erb.deface"
85
+ create_file example_file_path do <<-RUBY
86
+ <!-- insert_bottom 'body' -->
87
+ <div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>
88
+ #{NAME} active - edit/remove this file:<br/>
89
+ <strong>#{PATH}/#{example_file_path}</strong><br/>
90
+ <%= link_to 'deface docs', 'https://github.com/railsdog/deface', target: '_blank' %>
91
+ </div>
92
+ RUBY
93
+ end
94
+ end
95
+
96
+ def add_assets_override
97
+ create_file 'app/overrides/layouts/application/assets.html.erb.deface' do <<-RUBY
98
+ <!-- insert_bottom 'head' -->
99
+ <%= stylesheet_link_tag '#{NAME}/application' %>
100
+ <%= javascript_include_tag '#{NAME}/application' %>
101
+ RUBY
102
+ end
103
+ end
104
+ end
@@ -10,4 +10,4 @@
10
10
  *
11
11
  *= require_self
12
12
  *= require_tree .
13
- */
13
+ */
@@ -7,17 +7,16 @@ require "chili_template/version"
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "chili_template"
9
9
  s.version = ChiliTemplate::VERSION
10
- s.authors = ["Jens Balvig"]
11
- s.email = ["jens@cookpad.com"]
10
+ s.authors = ["GIT_AUTHOR"]
11
+ s.email = ["GIT_EMAIL"]
12
12
  s.homepage = ""
13
13
  s.summary = "Summary of ChiliTemplate."
14
14
  s.description = "Description of ChiliTemplate."
15
15
 
16
16
  s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
17
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
17
 
19
- s.add_dependency "rails", "~> 3.2.3"
20
- s.add_dependency 'chili', '~> 0.2.2'
18
+ s.add_dependency "rails", "~> 3.2.5"
19
+ s.add_dependency 'chili', '~> 0.3.0'
21
20
 
22
21
  s.add_development_dependency "sqlite3"
23
22
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ChiliGenerator' do
4
+ describe 'rails g chili EXTENSION_NAME' do
5
+ let(:app_path) { File.expand_path("../../../dummy/example", __FILE__) }
6
+ let(:template_path) { File.expand_path("../../../dummy/template", __FILE__) }
7
+
8
+ before do
9
+ FileUtils.rm_rf File.join(app_path, 'vendor/chili_template')
10
+ FileUtils.rm_rf File.join(app_path, 'Gemfile')
11
+ FileUtils.touch File.join(app_path, 'Gemfile')
12
+ end
13
+
14
+ it 'creates a new extension with a correct file structure' do
15
+ puts `cd #{app_path} && rails g chili template`
16
+
17
+ Dir.glob(File.join(template_path, "**/*")).reject { |f| File.directory?(f) }.each do |template|
18
+ result = File.join(app_path, 'vendor/chili_template', template.sub(template_path, ''))
19
+ result_text = File.open(result, 'rb').read
20
+ template_text = File.open(template, 'rb').read
21
+ template_text.sub!('GIT_AUTHOR',`git config user.name`.chomp) # Git author is be different on each machine
22
+ template_text.sub!('GIT_EMAIL',`git config user.email`.chomp) # Git email is be different on each machine
23
+ result_text.should == template_text
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chili
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70189184713320 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70189184713320
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: deface
27
- requirement: &70189184712820 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.9.1
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70189184712820
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.1
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70189184712340 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.9.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70189184712340
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec-rails
49
- requirement: &70189184711880 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 2.9.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70189184711880
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.9.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: jquery-rails
60
- requirement: &70189184711460 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70189184711460
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: capybara
71
- requirement: &70189184710880 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70189184710880
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: sqlite3
82
- requirement: &70189184710380 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,34 +117,37 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70189184710380
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  description: The spicy extension framework
92
127
  email:
93
128
  - jens@balvig.com
94
- executables:
95
- - chili
129
+ executables: []
96
130
  extensions: []
97
131
  extra_rdoc_files: []
98
132
  files:
99
133
  - .gitignore
134
+ - .travis.yml
100
135
  - Gemfile
101
136
  - LICENSE
102
137
  - README.md
103
138
  - Rakefile
104
139
  - app/controllers/chili/application_controller.rb
105
- - bin/chili
106
140
  - chili.gemspec
107
141
  - lib/chili.rb
108
142
  - lib/chili/activatable.rb
109
143
  - lib/chili/engine.rb
110
144
  - lib/chili/extensions/rails/engine.rb
111
145
  - lib/chili/overrides.rb
112
- - lib/chili/tasks.rb
113
- - lib/chili/template.rb
114
146
  - lib/chili/version.rb
147
+ - lib/generators/chili/USAGE
148
+ - lib/generators/chili/chili_generator.rb
115
149
  - lib/generators/rails/chili_generator.rb
116
150
  - lib/generators/rails/templates/controller.rb
117
- - spec/bin/chili_spec.rb
118
151
  - spec/dummy/example/README.rdoc
119
152
  - spec/dummy/example/Rakefile
120
153
  - spec/dummy/example/app/assets/javascripts/application.js
@@ -201,6 +234,7 @@ files:
201
234
  - spec/dummy/template/lib/chili_template/version.rb
202
235
  - spec/dummy/template/lib/tasks/chili_template_tasks.rake
203
236
  - spec/dummy/template/script/rails
237
+ - spec/generators/chili/chili_generator_spec.rb
204
238
  - spec/lib/chili/activatable_spec.rb
205
239
  - spec/requests/chili_social_spec.rb
206
240
  - spec/spec_helper.rb
@@ -218,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
252
  version: '0'
219
253
  segments:
220
254
  - 0
221
- hash: 385854585272327348
255
+ hash: -3078710322112426020
222
256
  required_rubygems_version: !ruby/object:Gem::Requirement
223
257
  none: false
224
258
  requirements:
@@ -227,15 +261,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
261
  version: '0'
228
262
  segments:
229
263
  - 0
230
- hash: 385854585272327348
264
+ hash: -3078710322112426020
231
265
  requirements: []
232
266
  rubyforge_project:
233
- rubygems_version: 1.8.11
267
+ rubygems_version: 1.8.23
234
268
  signing_key:
235
269
  specification_version: 3
236
270
  summary: The spicy extension framework
237
271
  test_files:
238
- - spec/bin/chili_spec.rb
239
272
  - spec/dummy/example/README.rdoc
240
273
  - spec/dummy/example/Rakefile
241
274
  - spec/dummy/example/app/assets/javascripts/application.js
@@ -322,6 +355,7 @@ test_files:
322
355
  - spec/dummy/template/lib/chili_template/version.rb
323
356
  - spec/dummy/template/lib/tasks/chili_template_tasks.rake
324
357
  - spec/dummy/template/script/rails
358
+ - spec/generators/chili/chili_generator_spec.rb
325
359
  - spec/lib/chili/activatable_spec.rb
326
360
  - spec/requests/chili_social_spec.rb
327
361
  - spec/spec_helper.rb
data/bin/chili DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- template_file = File.join(File.dirname(__FILE__), '..', 'lib', 'chili', 'template.rb')
4
- system "rails plugin new vendor/chili_#{ARGV.last} --mountable -m #{template_file}"
@@ -1,7 +0,0 @@
1
- module Chili
2
- module Tasks
3
- # App tasks
4
- require 'rails'
5
- load 'rails/tasks/engine.rake'
6
- end
7
- end
@@ -1,87 +0,0 @@
1
- # Edit gemspec
2
- require File.expand_path('../version', __FILE__)
3
- gemspec = "#{name}.gemspec"
4
- gsub_file gemspec, '# s.add_dependency "jquery-rails"', "s.add_dependency 'chili', '~> #{Chili::VERSION}'"
5
- gsub_file gemspec, 'TODO: Your name', `git config user.name`.chomp
6
- gsub_file gemspec, 'TODO: Your email', `git config user.email`.chomp
7
- gsub_file gemspec, /TODO(:\s)?/, ''
8
- gsub_file gemspec, 'Dir["test/**/*"]', 's.files.grep(%r{^(test|spec|features)/})'
9
-
10
- # Add gem to main app Gemfile
11
- append_to_file "../../Gemfile", "gem '#{name}', path: '#{app_path}'"
12
-
13
- # Uses Chili::ApplicationController and the layout from the main app
14
- remove_dir "app/controllers/#{name}"
15
- remove_dir "app/helpers/#{name}"
16
- remove_dir 'app/views/layouts'
17
-
18
- # Uses Gemfile from main app
19
- remove_file 'Gemfile'
20
-
21
- # Replace Rakefile
22
- remove_file 'Rakefile'
23
-
24
- # Remove jquery stuff from application.js
25
- gsub_file "app/assets/javascripts/#{name}/application.js", "//= require jquery_ujs\n", ''
26
- gsub_file "app/assets/javascripts/#{name}/application.js", "//= require jquery\n", ''
27
-
28
- # Setup custom generator
29
- inject_into_file "lib/#{name}/engine.rb", after: "isolate_namespace #{name.camelcase}\n" do <<-RUBY
30
- config.generators do |g|
31
- g.scaffold_controller :chili
32
- end
33
- RUBY
34
- end
35
-
36
- # Remove dummy stuff
37
- remove_dir 'test'
38
-
39
- # Set up rspec
40
- inject_into_file "lib/#{name}/engine.rb", :after => " g.scaffold_controller :chili\n" do <<-RUBY
41
- g.test_framework :rspec, view_specs: false, routing_specs: false, controller_specs: false
42
- g.integration_tool :rspec
43
- RUBY
44
- end
45
-
46
- # Edit .gitignore
47
- gsub_file ".gitignore", /test\/dummy.*\n/, ''
48
-
49
- # Automount engine
50
- prepend_to_file 'config/routes.rb', "#{name.camelcase}::Engine.automount!\n"
51
-
52
- # Include chili libs
53
- prepend_to_file "lib/#{name}.rb" do <<-RUBY
54
- require "chili"
55
- RUBY
56
- end
57
-
58
-
59
- # Include active_if
60
- inject_into_file "lib/#{name}.rb", :after => "module #{name.camelcase}\n" do <<-RUBY
61
- extend Chili::Activatable
62
- active_if { logged_in? }
63
- RUBY
64
- end
65
-
66
- # Add dummy override
67
- example_file_path = "app/overrides/layouts/application/example.html.erb.deface"
68
- create_file example_file_path do <<-RUBY
69
- <!-- insert_bottom 'body' -->
70
- <div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>
71
- #{name} active - edit/remove this file:<br/>
72
- <strong>#{app_path}/#{example_file_path}</strong><br/>
73
- <%= link_to 'deface docs', 'https://github.com/railsdog/deface', target: '_blank' %>
74
- </div>
75
- RUBY
76
- end
77
-
78
- # Add assets override
79
- create_file 'app/overrides/layouts/application/assets.html.erb.deface' do <<-RUBY
80
- <!-- insert_bottom 'head' -->
81
- <%= stylesheet_link_tag '#{name}/application' %>
82
- <%= javascript_include_tag '#{name}/application' %>
83
- RUBY
84
- end
85
-
86
- # Disable bundler
87
- def run_bundle ; end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Chili Binary' do
4
- describe 'chili EXTENSION_NAME' do
5
- let(:chili) { File.expand_path("../../../bin/chili", __FILE__) }
6
- let(:app_path) { File.expand_path("../../dummy/example", __FILE__) }
7
- let(:template_path) { File.expand_path("../../dummy/template", __FILE__) }
8
-
9
- before do
10
- FileUtils.rm_rf File.join(app_path, 'vendor/chili_template')
11
- FileUtils.rm_rf File.join(app_path, 'Gemfile')
12
- FileUtils.touch File.join(app_path, 'Gemfile')
13
- end
14
-
15
- it 'creates a new extension with a correct file structure' do
16
- `cd #{app_path} && #{chili} new template`
17
-
18
- Dir.glob(File.join(template_path, "**/*")).reject { |f| File.directory?(f) }.each do |source|
19
- result = File.join(app_path, 'vendor/chili_template', source.sub(template_path, ''))
20
- File.open(result, 'rb').read.should == File.open(source, 'rb').read
21
- end
22
- end
23
- end
24
- end