chili 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  The spicy extension framework
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'chili'
10
-
11
5
  ## Roadmap
12
6
 
13
7
  ### Core features
@@ -20,22 +14,101 @@ Unobtrusively(!)...
20
14
  - add new views and show/hide conditionally `done`
21
15
  - conditionally add to/edit existing views `done`
22
16
  - add methods to existing models `done`
17
+ - add new stylesheets and javascripts `done`
23
18
  - modify existing controller actions
24
19
 
25
- ### Utility features
26
-
27
- - make request specs understand paths
28
- - documentation
29
-
30
20
  ### Obstacles
31
21
 
32
- - resource route generator adds routes both to engine and main routes file
22
+ - Resource route generator adds routes both to engine and main routes file
33
23
  - Deface caches overrides in production. Monkey patch?
34
- - Have to add gemspec to main app
35
24
 
36
25
  ### Minor niggles
37
26
 
27
+ - Have to add gemspec to main app
38
28
  - Can only have one override per engine per partial due to the way I'm grabbing the class from the override
39
- - Where to get the database.yml file from?
40
- - Rspec generators don't namespace properly
41
29
  - Need to use DSL branch from deface
30
+ - Have to restart server when adding overrides
31
+ - Request specs don't have access to path helpers
32
+
33
+ ## Docs...
34
+
35
+ ### Creating a new chili extension
36
+
37
+ Assuming you want to add a new extension that adds "like" capabilities to a subset of users, run:
38
+
39
+ chili likes
40
+
41
+ This is basically a shortcut for running the rails engine generator with
42
+ a custom template:
43
+
44
+ rails plugin new chili_likes --mountable -m https://raw.github.com/balvig/chili/master/lib/chili/template.rb
45
+
46
+ ### Prepare main app
47
+
48
+ - make sure that shared views (f.ex layouts) uses `main_app.` prefix for routes
49
+ - add `gem 'deface', git: 'git://github.com/railsdog/deface.git', branch: 'dsl'` to Gemfile
50
+ - add `gemspec path: '../'` to Gemfile
51
+ - bundle
52
+ - set up database
53
+
54
+ ### Setting up activation conditions
55
+
56
+ Use the active_if block to control whether new controllers/overrides are visible or not.
57
+ The context of the active_if block is the application controller so you can use any methods available to that.
58
+
59
+ ```ruby
60
+ # lib/chili_likes.rb
61
+ module ChiliLikes
62
+ extend Chili::Activatable
63
+ active_if { logged_in? && current_user.admin? } # Extension is only visible to logged in admin users
64
+ end
65
+ ```
66
+
67
+ ### Modifying view templates in main app
68
+
69
+ See [deface docs](https://github.com/railsdog/deface#readme) for details.
70
+ As an example, assuming the main app has a partial at `app/views/posts/_post.html.erb`:
71
+
72
+ ```erb
73
+ <% # app/overrides/posts/_post/chili_likes.html.erb.deface (folder should mimic main app view path) %>
74
+ <!-- insert_bottom 'li' -->
75
+ <%= link_to 'Show likes', chili_likes.likes_path %>
76
+ ```
77
+
78
+ ### Adding new resources
79
+
80
+ Use `rails g scaffold Like` as usual when using engines. The new resource will be namespaced to ChiliLikes::Like
81
+ and automounted in the main app at `/chili_extension/likes` if active_if is true. All the rules for using
82
+ [engine-based models](http://railscasts.com/episodes/277-mountable-engines?view=asciicast) apply.
83
+
84
+ ### Modifying existing models
85
+
86
+ Create a model with the same name as the one you want to modify: `rails g model User --migration=false`
87
+ and inherit from the original:
88
+
89
+ ```ruby
90
+ # app/model/chili_likes/user.rb
91
+ module ChiliLikes
92
+ class User < ::User
93
+ has_many :likes
94
+ end
95
+ end
96
+ ```
97
+
98
+ Access through the namespaced model:
99
+
100
+ ```erb
101
+ <%= ChiliLikes::User.first.likes %>
102
+ <%= current_user.becomes(ChiliLikes::User).likes %>
103
+ ```
104
+
105
+ ### Adding new stylesheets/javascripts
106
+
107
+ Add files as usual in `app/assets/chili_likes/javascripts|stylesheets` and inject them into the layout using an override:
108
+
109
+ ```erb
110
+ <% # app/overrides/layouts/application/chili_likes.html.erb.deface %>
111
+ <!-- insert_bottom 'head' -->
112
+ <%= stylesheet_link_tag 'chili_likes/application' %>
113
+ <%= javascript_include_tag 'chili_likes/application' %>
114
+ ```
data/bin/chili ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ system "rails plugin new chili_#{ARGV.first} --mountable -m https://raw.github.com/balvig/chili/master/lib/chili/template.rb"
@@ -1,6 +1,6 @@
1
1
  # Add main app as submodule
2
2
  # For some reason root when using git method is test/dummy so doing this manually
3
- main_app_git_repo = ask("Where is the main app located?")
3
+ main_app_git_repo = ask("Where is the main app repository located?")
4
4
  run "cd #{destination_root} && git init"
5
5
  run "cd #{destination_root} && git submodule add #{main_app_git_repo} main_app"
6
6
 
data/lib/chili/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chili
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-09 00:00:00.000000000 Z
12
+ date: 2012-05-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: The spicy extension framework (work in progress)
15
15
  email:
16
16
  - jens@balvig.com
17
- executables: []
17
+ executables:
18
+ - chili
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
@@ -24,6 +25,7 @@ files:
24
25
  - README.md
25
26
  - Rakefile
26
27
  - app/controllers/chili/application_controller.rb
28
+ - bin/chili
27
29
  - chili.gemspec
28
30
  - lib/chili.rb
29
31
  - lib/chili/activatable.rb
@@ -46,21 +48,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
48
  - - ! '>='
47
49
  - !ruby/object:Gem::Version
48
50
  version: '0'
49
- segments:
50
- - 0
51
- hash: -1639324054153659084
52
51
  required_rubygems_version: !ruby/object:Gem::Requirement
53
52
  none: false
54
53
  requirements:
55
54
  - - ! '>='
56
55
  - !ruby/object:Gem::Version
57
56
  version: '0'
58
- segments:
59
- - 0
60
- hash: -1639324054153659084
61
57
  requirements: []
62
58
  rubyforge_project:
63
- rubygems_version: 1.8.23
59
+ rubygems_version: 1.8.11
64
60
  signing_key:
65
61
  specification_version: 3
66
62
  summary: The spicy extension framework (work in progress)