chili 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/.gitignore +7 -7
  2. data/README.md +33 -28
  3. data/Rakefile +1 -1
  4. data/app/controllers/chili/application_controller.rb +3 -3
  5. data/chili.gemspec +3 -3
  6. data/lib/chili.rb +5 -3
  7. data/lib/chili/feature.rb +15 -0
  8. data/lib/chili/version.rb +1 -1
  9. data/lib/generators/chili/feature/USAGE +8 -0
  10. data/lib/generators/chili/{extension_generator.rb → feature/feature_generator.rb} +36 -37
  11. data/lib/generators/chili/generator_proxy.rb +20 -0
  12. data/spec/dummy/app/app/controllers/application_controller.rb +3 -0
  13. data/spec/dummy/app/config/application.rb +14 -0
  14. data/spec/dummy/{example_app → app}/config/boot.rb +1 -2
  15. data/spec/dummy/{example_app → app}/config/database.yml +0 -0
  16. data/spec/dummy/{example_app → app}/config/environment.rb +0 -0
  17. data/spec/dummy/{example_app → app}/config/environments/development.rb +0 -0
  18. data/spec/dummy/{example_app → app}/config/environments/test.rb +0 -0
  19. data/spec/dummy/{example_app → app}/script/rails +0 -0
  20. data/spec/dummy/{blank_extension → blank_feature}/MIT-LICENSE +0 -0
  21. data/spec/dummy/blank_feature/README.rdoc +3 -0
  22. data/spec/dummy/{blank_extension/app/assets/images/blank_extension → blank_feature/app/assets/images/blank_feature}/.gitkeep +0 -0
  23. data/spec/dummy/{blank_extension/app/assets/javascripts/blank_extension → blank_feature/app/assets/javascripts/blank_feature}/application.js +0 -0
  24. data/spec/dummy/{blank_extension/app/assets/stylesheets/blank_extension → blank_feature/app/assets/stylesheets/blank_feature}/application.css +0 -0
  25. data/spec/dummy/blank_feature/app/controllers/blank_feature/application_controller.rb +4 -0
  26. data/spec/dummy/blank_feature/app/overrides/layouts/application/assets.html.erb.deface +3 -0
  27. data/spec/dummy/{blank_extension → blank_feature}/app/overrides/layouts/application/example.html.erb.deface +2 -2
  28. data/spec/dummy/{blank_extension/blank_extension.gemspec → blank_feature/blank_feature.gemspec} +6 -6
  29. data/spec/dummy/blank_feature/config/routes.rb +3 -0
  30. data/spec/dummy/blank_feature/lib/blank_feature.rb +7 -0
  31. data/spec/dummy/blank_feature/lib/blank_feature/engine.rb +5 -0
  32. data/spec/dummy/{blank_extension/lib/blank_extension → blank_feature/lib/blank_feature}/version.rb +1 -1
  33. data/spec/dummy/blank_feature/lib/generators/blank_feature_generator.rb +3 -0
  34. data/spec/dummy/{blank_extension/lib/tasks/blank_extension_tasks.rake → blank_feature/lib/tasks/blank_feature_tasks.rake} +1 -1
  35. data/spec/{dummy/example_app → example_app}/README.rdoc +0 -0
  36. data/spec/{dummy/example_app → example_app}/Rakefile +0 -0
  37. data/spec/{dummy/example_app → example_app}/app/assets/javascripts/application.js +0 -0
  38. data/spec/{dummy/example_app → example_app}/app/assets/stylesheets/application.css +0 -0
  39. data/spec/{dummy/example_app → example_app}/app/assets/stylesheets/posts.css +0 -0
  40. data/spec/{dummy/example_app → example_app}/app/assets/stylesheets/scaffold.css +0 -0
  41. data/spec/{dummy/example_app → example_app}/app/assets/stylesheets/users.css +0 -0
  42. data/spec/{dummy/example_app → example_app}/app/controllers/application_controller.rb +0 -0
  43. data/spec/{dummy/example_app → example_app}/app/controllers/posts_controller.rb +0 -0
  44. data/spec/{dummy/example_app → example_app}/app/controllers/sessions_controller.rb +0 -0
  45. data/spec/{dummy/example_app → example_app}/app/controllers/users_controller.rb +0 -0
  46. data/spec/{dummy/example_app → example_app}/app/helpers/application_helper.rb +0 -0
  47. data/spec/{dummy/example_app → example_app}/app/helpers/posts_helper.rb +0 -0
  48. data/spec/{dummy/example_app → example_app}/app/helpers/users_helper.rb +0 -0
  49. data/spec/{dummy/example_app → example_app}/app/mailers/.gitkeep +0 -0
  50. data/spec/{dummy/example_app → example_app}/app/models/.gitkeep +0 -0
  51. data/spec/{dummy/example_app → example_app}/app/models/post.rb +0 -0
  52. data/spec/{dummy/example_app → example_app}/app/models/user.rb +0 -0
  53. data/spec/{dummy/example_app → example_app}/app/views/layouts/application.html.erb +0 -0
  54. data/spec/{dummy/example_app → example_app}/app/views/posts/_form.html.erb +0 -0
  55. data/spec/{dummy/example_app → example_app}/app/views/posts/_post.html.erb +0 -0
  56. data/spec/{dummy/example_app → example_app}/app/views/posts/edit.html.erb +0 -0
  57. data/spec/{dummy/example_app → example_app}/app/views/posts/index.html.erb +0 -0
  58. data/spec/{dummy/example_app → example_app}/app/views/posts/new.html.erb +0 -0
  59. data/spec/{dummy/example_app → example_app}/app/views/posts/show.html.erb +0 -0
  60. data/spec/{dummy/example_app → example_app}/app/views/sessions/new.html.erb +0 -0
  61. data/spec/{dummy/example_app → example_app}/app/views/users/_form.html.erb +0 -0
  62. data/spec/{dummy/example_app → example_app}/app/views/users/edit.html.erb +0 -0
  63. data/spec/{dummy/example_app → example_app}/app/views/users/index.html.erb +0 -0
  64. data/spec/{dummy/example_app → example_app}/app/views/users/new.html.erb +0 -0
  65. data/spec/{dummy/example_app → example_app}/app/views/users/show.html.erb +0 -0
  66. data/spec/{dummy/example_app → example_app}/config.ru +0 -0
  67. data/spec/{dummy/example_app → example_app}/config/application.rb +2 -2
  68. data/spec/example_app/config/boot.rb +12 -0
  69. data/spec/example_app/config/database.yml +25 -0
  70. data/spec/example_app/config/environment.rb +5 -0
  71. data/spec/example_app/config/environments/development.rb +37 -0
  72. data/spec/{dummy/example_app → example_app}/config/environments/production.rb +0 -0
  73. data/spec/example_app/config/environments/test.rb +37 -0
  74. data/spec/{dummy/example_app → example_app}/config/initializers/backtrace_silencers.rb +0 -0
  75. data/spec/{dummy/example_app → example_app}/config/initializers/inflections.rb +0 -0
  76. data/spec/{dummy/example_app → example_app}/config/initializers/mime_types.rb +0 -0
  77. data/spec/{dummy/example_app → example_app}/config/initializers/secret_token.rb +0 -0
  78. data/spec/{dummy/example_app → example_app}/config/initializers/session_store.rb +0 -0
  79. data/spec/{dummy/example_app → example_app}/config/initializers/wrap_parameters.rb +0 -0
  80. data/spec/{dummy/example_app → example_app}/config/locales/en.yml +0 -0
  81. data/spec/{dummy/example_app → example_app}/config/routes.rb +0 -0
  82. data/spec/{dummy/example_app → example_app}/db/migrate/20120513023816_create_posts.rb +0 -0
  83. data/spec/{dummy/example_app → example_app}/db/migrate/20120513023840_create_users.rb +0 -0
  84. data/spec/example_app/db/migrate/20120513032032_create_social_feature_likes.rb +11 -0
  85. data/spec/{dummy/example_app → example_app}/db/schema.rb +1 -1
  86. data/spec/{dummy/example_app → example_app}/lib/assets/.gitkeep +0 -0
  87. data/spec/{dummy/example_app/vendor/chili/invites_extension → example_app/lib/chili/invites_feature}/.gitignore +0 -0
  88. data/spec/{dummy/example_app/log → example_app/lib/chili/invites_feature/app/assets/images/invites_feature}/.gitkeep +0 -0
  89. data/spec/{dummy/example_app/vendor/chili/invites_extension/app/assets/javascripts/invites_extension → example_app/lib/chili/invites_feature/app/assets/javascripts/invites_feature}/application.js +0 -0
  90. data/spec/{dummy/example_app/vendor/chili/invites_extension/app/assets/stylesheets/invites_extension → example_app/lib/chili/invites_feature/app/assets/stylesheets/invites_feature}/application.css +0 -0
  91. data/spec/example_app/lib/chili/invites_feature/app/controllers/invites_feature/application_controller.rb +4 -0
  92. data/spec/{dummy/example_app/vendor/chili/invites_extension → example_app/lib/chili/invites_feature}/app/overrides/posts/index/disclaimer.html.erb.deface +0 -0
  93. data/spec/example_app/lib/chili/invites_feature/config/routes.rb +3 -0
  94. data/spec/example_app/lib/chili/invites_feature/lib/generators/invites_feature_generator.rb +3 -0
  95. data/spec/{dummy/example_app/vendor/chili/invites_extension/lib/invites_extension.rb → example_app/lib/chili/invites_feature/lib/invites_feature.rb} +2 -2
  96. data/spec/example_app/lib/chili/invites_feature/lib/invites_feature/engine.rb +5 -0
  97. data/spec/{dummy/example_app/vendor/chili/invites_extension/app/assets/images/invites_extension → example_app/lib/chili/social_feature/app/assets/images/social_feature}/.gitkeep +0 -0
  98. data/spec/{dummy/example_app/vendor/chili/social_extension/app/assets/javascripts/social_extension → example_app/lib/chili/social_feature/app/assets/javascripts/social_feature}/application.js +0 -0
  99. data/spec/{dummy/example_app/vendor/chili/social_extension/app/assets/stylesheets/social_extension → example_app/lib/chili/social_feature/app/assets/stylesheets/social_feature}/application.css.scss +0 -0
  100. data/spec/example_app/lib/chili/social_feature/app/controllers/social_feature/application_controller.rb +4 -0
  101. data/spec/{dummy/example_app/vendor/chili/social_extension/app/controllers/social_extension → example_app/lib/chili/social_feature/app/controllers/social_feature}/likes_controller.rb +3 -3
  102. data/spec/{dummy/example_app/vendor/chili/social_extension/app/models/social_extension → example_app/lib/chili/social_feature/app/models/social_feature}/like.rb +1 -1
  103. data/spec/{dummy/example_app/vendor/chili/social_extension/app/models/social_extension → example_app/lib/chili/social_feature/app/models/social_feature}/post.rb +1 -1
  104. data/spec/{dummy/example_app/vendor/chili/social_extension/app/models/social_extension → example_app/lib/chili/social_feature/app/models/social_feature}/user.rb +1 -1
  105. data/spec/example_app/lib/chili/social_feature/app/overrides/layouts/application/likes_link.html.erb.deface +2 -0
  106. data/spec/{dummy/example_app/vendor/chili/social_extension → example_app/lib/chili/social_feature}/app/overrides/posts/_post/like_actions.html.erb.deface +2 -2
  107. data/spec/{dummy/example_app/vendor/chili/social_extension → example_app/lib/chili/social_feature}/app/overrides/posts/index/disclaimer.html.erb.deface +0 -0
  108. data/spec/{dummy/example_app/vendor/chili/social_extension → example_app/lib/chili/social_feature}/app/overrides/posts/index/table_headers.html.erb.deface +0 -0
  109. data/spec/{dummy/example_app/vendor/chili/social_extension/app/views/social_extension → example_app/lib/chili/social_feature/app/views/social_feature}/likes/index.html.erb +0 -0
  110. data/spec/example_app/lib/chili/social_feature/config/routes.rb +4 -0
  111. data/spec/example_app/lib/chili/social_feature/db/migrate/20120513031021_create_social_feature_likes.rb +10 -0
  112. data/spec/example_app/lib/chili/social_feature/lib/generators/social_feature_generator.rb +3 -0
  113. data/spec/{dummy/example_app/vendor/chili/social_extension/lib/social_extension.rb → example_app/lib/chili/social_feature/lib/social_feature.rb} +2 -2
  114. data/spec/example_app/lib/chili/social_feature/lib/social_feature/engine.rb +5 -0
  115. data/spec/{dummy/example_app/vendor/chili/social_extension/app/assets/images/social_extension → example_app/log}/.gitkeep +0 -0
  116. data/spec/{dummy/example_app → example_app}/public/404.html +0 -0
  117. data/spec/{dummy/example_app → example_app}/public/422.html +0 -0
  118. data/spec/{dummy/example_app → example_app}/public/500.html +0 -0
  119. data/spec/{dummy/example_app → example_app}/public/favicon.ico +0 -0
  120. data/spec/example_app/script/rails +6 -0
  121. data/spec/{dummy/example_app → example_app}/spec/support/user_macros.rb +0 -0
  122. data/spec/generators/chili/feature_generator_spec.rb +40 -0
  123. data/spec/generators/chili/generator_proxy_spec.rb +28 -0
  124. data/spec/requests/social_extension_spec.rb +5 -5
  125. data/spec/spec_helper.rb +2 -1
  126. data/spec/support/dummy_app.rb +21 -0
  127. metadata +251 -256
  128. data/lib/generators/chili/USAGE +0 -8
  129. data/lib/generators/rails/chili_generator.rb +0 -11
  130. data/lib/generators/rails/templates/controller.rb +0 -73
  131. data/spec/dummy/blank_extension/README.rdoc +0 -3
  132. data/spec/dummy/blank_extension/app/overrides/layouts/application/assets.html.erb.deface +0 -3
  133. data/spec/dummy/blank_extension/config/routes.rb +0 -3
  134. data/spec/dummy/blank_extension/lib/blank_extension.rb +0 -7
  135. data/spec/dummy/blank_extension/lib/blank_extension/engine.rb +0 -10
  136. data/spec/dummy/blank_extension/script/rails +0 -8
  137. data/spec/dummy/example_app/db/migrate/20120513032032_create_social_extension_likes.rb +0 -11
  138. data/spec/dummy/example_app/vendor/chili/invites_extension/config/routes.rb +0 -3
  139. data/spec/dummy/example_app/vendor/chili/invites_extension/lib/invites_extension/engine.rb +0 -10
  140. data/spec/dummy/example_app/vendor/chili/social_extension/app/overrides/layouts/application/likes_link.html.erb.deface +0 -2
  141. data/spec/dummy/example_app/vendor/chili/social_extension/config/routes.rb +0 -4
  142. data/spec/dummy/example_app/vendor/chili/social_extension/db/migrate/20120513031021_create_likes_extension_likes.rb +0 -10
  143. data/spec/dummy/example_app/vendor/chili/social_extension/lib/social_extension/engine.rb +0 -10
  144. data/spec/generators/chili/chili_generator_spec.rb +0 -53
data/.gitignore CHANGED
@@ -12,13 +12,13 @@ lib/bundler/man
12
12
  pkg
13
13
  rdoc
14
14
  spec/reports
15
- spec/dummy/example_app/db/*.sqlite3
16
- spec/dummy/example_app/log/*.log
17
- spec/dummy/example_app/tmp/
18
- spec/dummy/example_app/.sass-cache
19
- spec/dummy/example_app/vendor/chili/blank_extension
20
- spec/dummy/example_app/vendor/chili/another_blank_extension
21
- spec/dummy/example_app/Gemfile
15
+ spec/example_app/db/*.sqlite3
16
+ spec/example_app/log/*.log
17
+ spec/example_app/tmp/
18
+ spec/example_app/.sass-cache
19
+ spec/dummy/app/Gemfile
20
+ spec/dummy/app/log/
21
+ spec/dummy/app/lib/
22
22
  tmp
23
23
  .DS_Store
24
24
  .pt
data/README.md CHANGED
@@ -28,32 +28,32 @@ and run `bundle`.
28
28
 
29
29
  ## Usage
30
30
 
31
- Chili extensions are like mini apps that are created inside your main app's vendor directory using using the "chili" generator.
31
+ Chili features are like mini apps that are created inside your main app's lib/chili directory using using the "chili" generator.
32
32
 
33
- ### Creating a new chili extension
33
+ ### Creating a new chili feature
34
34
 
35
- 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
35
+ As an example, assuming you want to add a beta feature named "social" that shows a new like-button
36
36
  to a subset of users, first within your main app run:
37
37
 
38
- $ rails g chili:extension social
38
+ $ rails g chili:feature social
39
39
 
40
40
  This will:
41
41
 
42
- 1. Create the directory `vendor/chili/social_extension` containing the basic structure for the extension
43
- 2. Add a reference to the extension to the main app gemfile
42
+ 1. Create the directory `lib/chili/social_feature` containing the basic structure for the feature
43
+ 2. Add a reference to the feature to the main app gemfile
44
44
 
45
- Since the extension is mounted as a gem you'll have to restart the app.
45
+ Since the feature is mounted as a gem you'll have to restart the app.
46
46
 
47
- ### Define who can see the extension
47
+ ### Define who can see the feature
48
48
 
49
- Use the active_if block to control whether new the extension is active for each user.
49
+ Use the active_if block to control whether new the feature is active for each user.
50
50
  The context of the active_if block is the application controller so you can use any methods available to that.
51
51
 
52
52
  ```ruby
53
- # lib/social_extension.rb
54
- module SocialExtension
53
+ # lib/social_feature.rb
54
+ module SocialFeature
55
55
  extend Chili::Activatable
56
- active_if { logged_in? && current_user.admin? } # Extension is only visible to logged in admin users
56
+ active_if { logged_in? && current_user.admin? } # Feature is only visible to logged in admin users
57
57
  end
58
58
  ```
59
59
 
@@ -66,56 +66,61 @@ For example, assuming the main app has the partial `app/views/posts/_post.html.e
66
66
  ```erb
67
67
  <% # app/overrides/posts/_post/like_button.html.erb.deface (folder should mirror main app view path) %>
68
68
  <!-- insert_bottom 'tr' -->
69
- <td><%= link_to 'Like!', social_extension.likes_path(like: {post_id: post}), method: :post %></td>
69
+ <td><%= link_to 'Like!', social_feature.likes_path(like: {post_id: post}), method: :post %></td>
70
70
  ```
71
71
 
72
72
  ### Adding new resources
73
73
 
74
- Run `rails g scaffold Like` from within the extension's directory. The new resource will be namespaced to `SocialExtension::Like`
75
- and automounted as an [isolated engine](http://railscasts.com/episodes/277-mountable-engines?view=asciicast) in the main app at `/chili/social_extension/likes`,
74
+ You can run the usual Rails generators for each feature by prepending
75
+ the generator with the name of the feature:
76
+
77
+ ```bash
78
+ $ rails g social_feature scaffold Like
79
+ ```
80
+
81
+ The new resource will be namespaced to `SocialFeature::Like` and automounted as an [isolated engine](http://railscasts.com/episodes/277-mountable-engines?view=asciicast) in the main app at `/chili/social_feature/likes`,
76
82
  but will only be accessible when active_if is true.
77
83
 
78
84
  ### Migrations
79
85
 
80
86
  Migrations are handled the same way as engines. Use the
81
- following commands after you've added a new migration to your extension:
87
+ following commands after you've added a new migration to a feature:
82
88
 
83
- $ rake social_extension:migrations:install
89
+ $ rake social_feature:migrations:install
84
90
  $ rake db:migrate
85
91
 
86
92
  ### Modifying existing models
87
93
 
88
- Create a model with the same name as the one you want to modify by running: `rails g model User --migration=false` inside your extension's directory
89
- and edit it to inherit from the original:
94
+ Create a model with the same name as the one you want to modify by running: `rails g social_feature model User --migration=false` and edit it to inherit from the original:
90
95
 
91
96
  ```ruby
92
- # app/models/social_extension/user.rb
93
- module SocialExtension
97
+ # app/models/social_feature/user.rb
98
+ module SocialFeature
94
99
  class User < ::User
95
100
  has_many :likes
96
101
  end
97
102
  end
98
103
  ```
99
104
 
100
- Access in your overrides/extension views through the namespaced model:
105
+ Access in your overrides/feature views through the namespaced model:
101
106
 
102
107
  ```erb
103
- <%= SocialExtension::User.first.likes %>
104
- <%= current_user.becomes(SocialExtension::User).likes %>
108
+ <%= SocialFeature::User.first.likes %>
109
+ <%= current_user.becomes(SocialFeature::User).likes %>
105
110
  ```
106
111
 
107
112
  ### Stylesheets/javascripts
108
113
 
109
- Files added to the extension's `app/assets/social_extension/javascripts|stylesheets` directory are automatically injected into the layout using a pre-generated override:
114
+ Files added to the feature's `app/assets/social_feature/javascripts|stylesheets` directory are automatically injected into the layout using a pre-generated override:
110
115
 
111
116
  ```erb
112
117
  <% # app/overrides/layouts/application/assets.html.erb.deface %>
113
118
  <!-- insert_bottom 'head' -->
114
- <%= stylesheet_link_tag 'social_extension/application' %>
115
- <%= javascript_include_tag 'social_extension/application' %>
119
+ <%= stylesheet_link_tag 'social_feature/application' %>
120
+ <%= javascript_include_tag 'social_feature/application' %>
116
121
  ```
117
122
 
118
- If you don't need any css/js in your extension, you can remove this file.
123
+ If you don't need any css/js in your feature, you can remove this file.
119
124
 
120
125
  ## Gotchas
121
126
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ 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/example_app/Rakefile", __FILE__)
9
+ APP_RAKEFILE = File.expand_path("../spec/example_app/Rakefile", __FILE__)
10
10
  load 'rails/tasks/engine.rake'
11
11
 
12
12
  require 'rspec/core/rake_task'
@@ -1,10 +1,10 @@
1
1
  module Chili
2
2
  class ApplicationController < ::ApplicationController
3
- before_filter :activate_extension
3
+ before_filter :activate_feature
4
4
 
5
5
  private
6
- def activate_extension
7
- raise ActionController::RoutingError, 'Extension Disabled' unless self.class.parent.active?(self)
6
+ def activate_feature
7
+ raise ActionController::RoutingError, 'Feature Disabled' unless self.class.parent.active?(self)
8
8
  end
9
9
  end
10
10
  end
@@ -4,8 +4,8 @@ require File.expand_path('../lib/chili/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Jens Balvig"]
6
6
  gem.email = ["jens@balvig.com"]
7
- gem.description = %q{The spicy extension framework}
8
- gem.summary = %q{The spicy extension framework}
7
+ gem.description = %q{The spicy feature toggle framework}
8
+ gem.summary = %q{The spicy feature toggle framework}
9
9
  gem.homepage = "http://balvig.github.com/chili/"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -22,5 +22,5 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency 'rspec-rails', '~> 2.9.0'
23
23
  gem.add_development_dependency 'jquery-rails'
24
24
  gem.add_development_dependency 'capybara'
25
- gem.add_development_dependency "sqlite3"
25
+ gem.add_development_dependency 'sqlite3'
26
26
  end
@@ -1,7 +1,9 @@
1
1
  require "deface"
2
- require "chili/version"
3
- require "chili/engine"
4
- require "chili/overrides"
5
2
  require "chili/activatable"
6
3
  require "chili/bundler"
4
+ require "chili/engine"
7
5
  require "chili/extensions/rails/engine"
6
+ require "chili/feature"
7
+ require "chili/overrides"
8
+ require "chili/version"
9
+ require "generators/chili/generator_proxy"
@@ -0,0 +1,15 @@
1
+ module Chili
2
+ class Feature
3
+ def initialize(short_name)
4
+ @short_name = short_name
5
+ end
6
+
7
+ def name
8
+ @short_name.to_s.underscore.gsub('_feature','') + '_feature'
9
+ end
10
+
11
+ def path
12
+ "lib/chili/#{name}"
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Chili
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a new chili feature
3
+
4
+ Example:
5
+ rails generate chili:feature social
6
+
7
+ This will create:
8
+ basic chili feature structure in vendor/chili/social_feature
@@ -1,12 +1,10 @@
1
1
  module Chili
2
2
  module Generators
3
- class ExtensionGenerator < Rails::Generators::NamedBase
4
- NAME = "#{ARGV[0]}_extension"
5
- PATH = "vendor/chili/#{NAME}"
3
+ class FeatureGenerator < Rails::Generators::NamedBase
6
4
 
7
5
  def run_plugin_generator
8
- ARGV[0] = PATH
9
- ARGV[1] = "--mountable"
6
+ ARGV[0] = feature.path
7
+ ARGV[1] = '--mountable'
10
8
  ARGV[2] = '--skip-test-unit'
11
9
  ARGV[3] = '--skip-bundle'
12
10
 
@@ -20,9 +18,9 @@ module Chili
20
18
  end
21
19
 
22
20
  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}'"
21
+ require File.expand_path('../../../../chili/version', __FILE__)
22
+ gemspec = "#{feature.name}.gemspec"
23
+ gsub_file gemspec, '# s.add_dependency "jquery-rails"', "s.add_dependency 'chili', '~> #{Chili::VERSION.sub(/\.\d+$/,'')}'"
26
24
  gsub_file gemspec, 'TODO: Your name', `git config user.NAME`.chomp
27
25
  gsub_file gemspec, 'TODO: Your email', `git config user.email`.chomp
28
26
  gsub_file gemspec, /TODO(:\s)?/, ''
@@ -32,38 +30,25 @@ module Chili
32
30
  gemfile = "../../../Gemfile"
33
31
  group = "group :chili do\n"
34
32
  append_to_file gemfile, group
35
- append_to_file gemfile, " gem '#{NAME}', path: '#{PATH}'\nend", after: group
33
+ append_to_file gemfile, " gem '#{feature.name}', path: '#{feature.path}'\nend", after: group
36
34
  gsub_file gemfile, 'end gem', ' gem' #nasty cleanup
37
35
  end
38
36
 
39
37
  def remove_unused_files
40
- remove_dir "app/controllers/#{NAME}"
41
- remove_dir "app/helpers/#{NAME}"
38
+ remove_dir "app/helpers/#{feature.name}"
42
39
  remove_dir 'app/views/layouts'
40
+ remove_dir 'script'
43
41
  remove_file 'Gemfile'
44
42
  remove_file 'Rakefile'
45
43
  end
46
44
 
47
45
  def remove_jquery_stuff
48
- gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery_ujs\n", ''
49
- gsub_file "app/assets/javascripts/#{NAME}/application.js", "//= require jquery\n", ''
46
+ gsub_file "app/assets/javascripts/#{feature.name}/application.js", "//= require jquery_ujs\n", ''
47
+ gsub_file "app/assets/javascripts/#{feature.name}/application.js", "//= require jquery\n", ''
50
48
  end
51
49
 
52
- def set_up_custom_generator
53
- inject_into_file "lib/#{NAME}/engine.rb", after: "isolate_namespace #{NAME.camelcase}\n" do <<-RUBY
54
- config.generators do |g|
55
- g.scaffold_controller :chili
56
- end
57
- RUBY
58
- end
59
- end
60
-
61
- def set_up_rspec
62
- inject_into_file "lib/#{NAME}/engine.rb", :after => " g.scaffold_controller :chili\n" do <<-RUBY
63
- g.test_framework :rspec, view_specs: false, routing_specs: false, controller_specs: false
64
- g.integration_tool :rspec
65
- RUBY
66
- end
50
+ def chilify_application_controller
51
+ gsub_file "app/controllers/#{feature.name}/application_controller.rb", "ActionController::Base", 'Chili::ApplicationController'
67
52
  end
68
53
 
69
54
  def clean_up_gitignore
@@ -71,17 +56,17 @@ module Chili
71
56
  end
72
57
 
73
58
  def automount_engine
74
- prepend_to_file 'config/routes.rb', "#{NAME.camelcase}::Engine.automount!\n"
59
+ prepend_to_file 'config/routes.rb', "#{feature.name.camelcase}::Engine.automount!\n"
75
60
  end
76
61
 
77
62
  def include_chili_libs
78
- prepend_to_file "lib/#{NAME}.rb", "require \"chili\"\n"
63
+ prepend_to_file "lib/#{feature.name}.rb", "require \"chili\"\n"
79
64
  end
80
65
 
81
66
  def include_active_if
82
- inject_into_file "lib/#{NAME}.rb", after: "module #{NAME.camelcase}\n" do <<-RUBY
67
+ inject_into_file "lib/#{feature.name}.rb", after: "module #{feature.name.camelcase}\n" do <<-RUBY
83
68
  extend Chili::Activatable
84
- active_if { true } # edit this to activate/deactivate extension at runtime
69
+ active_if { true } # edit this to activate/deactivate feature at runtime
85
70
  RUBY
86
71
  end
87
72
  end
@@ -91,8 +76,8 @@ module Chili
91
76
  create_file example_file_path do <<-RUBY
92
77
  <!-- insert_bottom 'body' -->
93
78
  <div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>
94
- #{NAME} active - edit/remove this file:<br/>
95
- <strong>#{PATH}/#{example_file_path}</strong><br/>
79
+ #{feature.name} active - edit/remove this file:<br/>
80
+ <strong>#{feature.path}/#{example_file_path}</strong><br/>
96
81
  <%= link_to 'deface docs', 'https://github.com/spree/deface', target: '_blank' %>
97
82
  </div>
98
83
  RUBY
@@ -102,12 +87,26 @@ module Chili
102
87
  def add_assets_override
103
88
  create_file 'app/overrides/layouts/application/assets.html.erb.deface' do <<-RUBY
104
89
  <!-- insert_bottom 'head' -->
105
- <%= stylesheet_link_tag '#{NAME}/application' %>
106
- <%= javascript_include_tag '#{NAME}/application' %>
90
+ <%= stylesheet_link_tag '#{feature.name}/application' %>
91
+ <%= javascript_include_tag '#{feature.name}/application' %>
107
92
  RUBY
108
93
  end
109
94
  end
110
- end
111
95
 
96
+ def add_generator_proxy
97
+ create_file "lib/generators/#{feature.name}_generator.rb" do <<-RUBY
98
+ class #{feature.name.camelcase}Generator < Rails::Generators::Base
99
+ include Chili::GeneratorProxy
100
+ end
101
+ RUBY
102
+ end
103
+ end
104
+
105
+ protected
106
+
107
+ def feature
108
+ @feature ||= Chili::Feature.new(ARGV[0])
109
+ end
110
+ end
112
111
  end
113
112
  end
@@ -0,0 +1,20 @@
1
+ module Chili
2
+ module GeneratorProxy
3
+ def self.included(base)
4
+ base.class_eval do
5
+ argument :generator, type: :string
6
+ argument :generator_options, type: :array, default: [], banner: "GENERATOR_OPTIONS"
7
+
8
+ def self.desc
9
+ "Generates resources (scaffold, model, migration etc) for #{generator_name}"
10
+ end
11
+
12
+ def delegate
13
+ engine = self.class.generator_name.classify.constantize
14
+ Rails::Generators.namespace = engine
15
+ Rails::Generators.invoke ARGV.shift, ARGV, destination_root: Feature.new(engine).path, behavior: behavior
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require
6
+ require "chili"
7
+ Dir.glob(File.expand_path('../../lib/chili/*', __FILE__)).each do |dir|
8
+ require File.basename(dir)
9
+ end
10
+
11
+ module Dummy
12
+ class Application < Rails::Application
13
+ end
14
+ end
@@ -8,5 +8,4 @@ if File.exist?(gemfile)
8
8
  end
9
9
 
10
10
  $:.unshift File.expand_path('../../../../../lib', __FILE__)
11
- $:.unshift File.expand_path('../../vendor/chili/social_extension/lib', __FILE__)
12
- $:.unshift File.expand_path('../../vendor/chili/invites_extension/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../lib/chili/blank_feature/lib', __FILE__)
@@ -0,0 +1,3 @@
1
+ = BlankFeature
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,4 @@
1
+ module BlankFeature
2
+ class ApplicationController < Chili::ApplicationController
3
+ end
4
+ end