chili 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/app/controllers/chili/application_controller.rb +10 -0
- data/chili.gemspec +17 -0
- data/lib/chili.rb +4 -0
- data/lib/chili/activatable.rb +11 -0
- data/lib/chili/engine.rb +9 -0
- data/lib/chili/overrides.rb +18 -0
- data/lib/chili/tasks.rb +19 -0
- data/lib/chili/template.rb +95 -0
- data/lib/chili/version.rb +3 -0
- data/lib/generators/rails/chili_generator.rb +11 -0
- data/lib/generators/rails/templates/controller.rb +73 -0
- metadata +67 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jens Balvig
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Chili
|
2
|
+
|
3
|
+
The spicy extension framework
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'chili'
|
10
|
+
|
11
|
+
## Roadmap
|
12
|
+
|
13
|
+
### Core features
|
14
|
+
|
15
|
+
Unobtrusively(!)...
|
16
|
+
|
17
|
+
- add new models `done`
|
18
|
+
- add new tables/migrations `done`
|
19
|
+
- add new controllers and show/hide conditionally `done`
|
20
|
+
- add new views and show/hide conditionally `done`
|
21
|
+
- conditionally add to/edit existing views `done`
|
22
|
+
- add methods to existing models `done`
|
23
|
+
- modify existing controller actions
|
24
|
+
|
25
|
+
### Utility features
|
26
|
+
|
27
|
+
- make request specs understand paths
|
28
|
+
- documentation
|
29
|
+
|
30
|
+
### Obstacles
|
31
|
+
|
32
|
+
- resource route generator adds routes both to engine and main routes file
|
33
|
+
- Deface caches overrides in production. Monkey patch?
|
34
|
+
- Have to add gemspec to main app
|
35
|
+
|
36
|
+
### Minor niggles
|
37
|
+
|
38
|
+
- 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
|
+
- Need to use DSL branch from deface
|
data/Rakefile
ADDED
data/chili.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/chili/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jens Balvig"]
|
6
|
+
gem.email = ["jens@balvig.com"]
|
7
|
+
gem.description = %q{The spicy extension framework (work in progress)}
|
8
|
+
gem.summary = %q{The spicy extension framework (work in progress)}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "chili"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Chili::VERSION
|
17
|
+
end
|
data/lib/chili.rb
ADDED
data/lib/chili/engine.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Chili
|
2
|
+
module Overrides
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:include, InstanceMethods)
|
5
|
+
base.before_filter :activate_overrides
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def activate_overrides
|
10
|
+
Deface::Override.all.each do |o|
|
11
|
+
engine = o.second.keys.first.camelcase.constantize
|
12
|
+
override = o.second.first.second
|
13
|
+
override.args[:disabled] = !engine.active?(self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/chili/tasks.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Chili
|
2
|
+
module Tasks
|
3
|
+
# Bundler
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
rescue LoadError
|
7
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
8
|
+
end
|
9
|
+
|
10
|
+
# App tasks
|
11
|
+
require 'rails'
|
12
|
+
load 'rails/tasks/engine.rake'
|
13
|
+
|
14
|
+
# Gem tasks
|
15
|
+
require 'bundler/gem_helper'
|
16
|
+
Bundler::GemHelper.install_tasks
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Add main app as submodule
|
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?")
|
4
|
+
run "cd #{destination_root} && git init"
|
5
|
+
run "cd #{destination_root} && git submodule add #{main_app_git_repo} main_app"
|
6
|
+
|
7
|
+
# Uses Chili::ApplicationController and the layout from the main app
|
8
|
+
remove_dir "app/controllers/#{app_path}"
|
9
|
+
remove_dir "app/helpers/#{app_path}"
|
10
|
+
remove_dir 'app/views/layouts'
|
11
|
+
|
12
|
+
# Uses Gemfile from main app
|
13
|
+
remove_file 'Gemfile'
|
14
|
+
|
15
|
+
# Replace Rakefile
|
16
|
+
remove_file 'Rakefile'
|
17
|
+
create_file 'Rakefile' do <<-RUBY
|
18
|
+
#!/usr/bin/env rake
|
19
|
+
APP_RAKEFILE = File.expand_path("../main_app/Rakefile", __FILE__)
|
20
|
+
require 'chili/tasks'
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
|
24
|
+
# Setup custom generator
|
25
|
+
inject_into_file "lib/#{app_path}/engine.rb", :after => "isolate_namespace #{app_path.camelcase}\n" do <<-RUBY
|
26
|
+
config.generators do |g|
|
27
|
+
g.scaffold_controller :chili
|
28
|
+
end
|
29
|
+
RUBY
|
30
|
+
end
|
31
|
+
|
32
|
+
# Setup rspec
|
33
|
+
remove_dir 'test'
|
34
|
+
create_file 'spec/spec_helper.rb' do <<-RUBY
|
35
|
+
ENV["RAILS_ENV"] ||= 'test'
|
36
|
+
require File.expand_path("../../main_app/config/environment", __FILE__)
|
37
|
+
require 'rspec/rails'
|
38
|
+
require 'rspec/autorun'
|
39
|
+
|
40
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
41
|
+
|
42
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
43
|
+
# in spec/support/ and its subdirectories in both main app and the extension.
|
44
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f }
|
45
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
append_to_file 'Rakefile' do <<-RUBY
|
50
|
+
|
51
|
+
# Default rake task to rspec
|
52
|
+
task default: 'app:spec'
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
inject_into_file "lib/#{app_path}/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
|
+
|
62
|
+
# Automount engine
|
63
|
+
append_to_file 'config/routes.rb' do <<-RUBY
|
64
|
+
|
65
|
+
# Automount engine
|
66
|
+
Rails.application.routes.draw do
|
67
|
+
mount #{app_path.camelcase}::Engine => "/#{app_path}"
|
68
|
+
end
|
69
|
+
RUBY
|
70
|
+
end
|
71
|
+
|
72
|
+
# Include chili libs
|
73
|
+
prepend_to_file "lib/#{app_path}.rb" do <<-RUBY
|
74
|
+
require "chili"
|
75
|
+
RUBY
|
76
|
+
end
|
77
|
+
|
78
|
+
gsub_file "#{app_path}.gemspec", '# s.add_dependency "jquery-rails"', 's.add_dependency "chili"'
|
79
|
+
|
80
|
+
# Include active_if
|
81
|
+
inject_into_file "lib/#{app_path}.rb", :after => "module #{app_path.camelcase}\n" do <<-RUBY
|
82
|
+
extend Chili::Activatable
|
83
|
+
active_if { logged_in? }
|
84
|
+
RUBY
|
85
|
+
end
|
86
|
+
|
87
|
+
# Add dummy override
|
88
|
+
create_file "app/overrides/layouts/application/#{app_path}.html.erb.deface" do <<-RUBY
|
89
|
+
<!-- insert_bottom 'body' -->
|
90
|
+
<div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>#{app_path} activated - <%= link_to 'deface docs', 'https://github.com/railsdog/deface', target: '_blank' %></div>
|
91
|
+
RUBY
|
92
|
+
end
|
93
|
+
|
94
|
+
# Disable bundler
|
95
|
+
def run_bundle ; end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class ChiliGenerator < ScaffoldControllerGenerator
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= controller_class_name %>Controller < Chili::ApplicationController
|
3
|
+
|
4
|
+
def index
|
5
|
+
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render json: <%= "@#{plural_table_name}" %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html # show.html.erb
|
18
|
+
format.json { render json: <%= "@#{singular_table_name}" %> }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def new
|
23
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
24
|
+
|
25
|
+
respond_to do |format|
|
26
|
+
format.html # new.html.erb
|
27
|
+
format.json { render json: <%= "@#{singular_table_name}" %> }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit
|
32
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
|
37
|
+
|
38
|
+
respond_to do |format|
|
39
|
+
if @<%= orm_instance.save %>
|
40
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
|
41
|
+
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> }
|
42
|
+
else
|
43
|
+
format.html { render action: "new" }
|
44
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
51
|
+
|
52
|
+
respond_to do |format|
|
53
|
+
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
|
54
|
+
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
55
|
+
format.json { head :no_content }
|
56
|
+
else
|
57
|
+
format.html { render action: "edit" }
|
58
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy
|
64
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
65
|
+
@<%= orm_instance.destroy %>
|
66
|
+
|
67
|
+
respond_to do |format|
|
68
|
+
format.html { redirect_to <%= index_helper %>_url }
|
69
|
+
format.json { head :no_content }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
<% end -%>
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chili
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jens Balvig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: The spicy extension framework (work in progress)
|
15
|
+
email:
|
16
|
+
- jens@balvig.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- app/controllers/chili/application_controller.rb
|
27
|
+
- chili.gemspec
|
28
|
+
- lib/chili.rb
|
29
|
+
- lib/chili/activatable.rb
|
30
|
+
- lib/chili/engine.rb
|
31
|
+
- lib/chili/overrides.rb
|
32
|
+
- lib/chili/tasks.rb
|
33
|
+
- lib/chili/template.rb
|
34
|
+
- lib/chili/version.rb
|
35
|
+
- lib/generators/rails/chili_generator.rb
|
36
|
+
- lib/generators/rails/templates/controller.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
hash: -1639324054153659084
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: -1639324054153659084
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.23
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: The spicy extension framework (work in progress)
|
67
|
+
test_files: []
|