fume 0.10.0a → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -5
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +11 -3
- data/Gemfile +1 -1
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +3 -5
- data/fume.gemspec +34 -25
- data/gemfiles/rails3_2.gemfile +6 -0
- data/lib/fume.rb +7 -5
- data/lib/fume/active_record_exts.rb +10 -0
- data/lib/fume/controller_exts.rb +35 -0
- data/lib/fume/helper_exts.rb +8 -0
- data/lib/fume/railtie.rb +5 -7
- data/lib/fume/render_cache.rb +26 -20
- data/lib/fume/require_accessor.rb +22 -0
- data/lib/fume/version.rb +3 -0
- data/spec/fume/controller_exts_spec.rb +60 -0
- data/spec/fume/helper_exts_spec.rb +17 -0
- data/spec/fume/render_cache_spec.rb +62 -0
- data/spec/fume/require_accessor_spec.rb +19 -0
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/app/models/page.rb +2 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +6 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +22 -8
- metadata +152 -34
- data/VERSION +0 -1
- data/lib/fume/app_setting_loader.rb +0 -12
- data/lib/fume/rails_ext.rb +0 -70
- data/lib/generators/fume/simple_scaffold/USAGE +0 -10
- data/lib/generators/fume/simple_scaffold/simple_scaffold_generator.rb +0 -44
- data/lib/generators/fume/simple_scaffold/templates/_form.html.erb +0 -7
- data/lib/generators/fume/simple_scaffold/templates/controller.rb +0 -44
- data/lib/generators/fume/simple_scaffold/templates/edit.html.erb +0 -5
- data/lib/generators/fume/simple_scaffold/templates/index.html.erb +0 -32
- data/lib/generators/fume/simple_scaffold/templates/new.html.erb +0 -5
- data/spec/spec.opts +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d01eede63fdda3019866d702fb8229f347bfbc
|
4
|
+
data.tar.gz: 6056e4c689516d952cd7f59fdcfcf891176c6dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a10457e43ac6bb7401c982e56597d70e0f43a4d2496f368150aba49903feb0642e485c1e6b6a01cb5b10235b253e47f8980106006ba5033486b04f715f66d4b9
|
7
|
+
data.tar.gz: e8d36377f06ad71b8bdb2f227669952b5fa7cb5546a80f2af9ab7acda9735b6fe7922db04086b67ff34e94ebd2ea58fc40e186b4336735363f2bd93db00afcda
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.10
|
2
|
+
- add require_accessor on model
|
3
|
+
- extract simple_nav to fume-nav gem
|
4
|
+
- remove app_setting_loader, use fume-settable instead of it.
|
5
|
+
- remove action_attr_accessor
|
6
|
+
- remove simple_scaffold generator
|
7
|
+
- refactor code structure
|
8
|
+
|
9
|
+
## 0.9
|
2
10
|
- extract cancan to standalone gem
|
3
11
|
- remove authlogic ext
|
4
12
|
|
5
|
-
## 0.8
|
13
|
+
## 0.8
|
6
14
|
- don't depends all rails plugin, you must depend it for yourself.
|
7
15
|
- upgrade rails to 3.1.0
|
8
16
|
|
9
|
-
## 0.7
|
17
|
+
## 0.7
|
10
18
|
- add action_attr_accessor method
|
11
19
|
- depend rails_i18n
|
12
20
|
- rename simple\_theme to simple_nav and rewirte
|
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 sunteya
|
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
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Fume
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sunteya/fume.svg?branch=master)](https://travis-ci.org/sunteya/fume)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/sunteya/fume/badge.png)](https://coveralls.io/r/sunteya/fume)
|
5
|
+
|
6
|
+
some simple rails extentions
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'fume'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
please read source code and spec file.
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. Fork it ( http://github.com/sunteya/fume/fork )
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/fume.gemspec
CHANGED
@@ -1,31 +1,40 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fume/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fume"
|
8
|
+
spec.version = Fume::VERSION
|
9
|
+
spec.authors = ["sunteya"]
|
10
|
+
spec.email = ["sunteya@gmail.com"]
|
11
|
+
spec.summary = %q{some simple rails extentions.}
|
12
|
+
spec.description = %q{some simple rails extentions.}
|
13
|
+
spec.homepage = "https://github.com/sunteya/fume"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.2.13"
|
22
|
+
spec.add_dependency "rails-i18n", ">= 0.7.2"
|
23
|
+
spec.add_dependency "hashie", ">= 1.2.0"
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec-rails", "~> 2.14.1"
|
29
|
+
spec.add_development_dependency "rspec-do_action", "~> 0.0.3"
|
30
|
+
spec.add_development_dependency "coveralls"
|
31
|
+
|
32
|
+
spec.add_development_dependency "pry-nav"
|
33
|
+
spec.add_development_dependency "sqlite3"
|
34
|
+
spec.add_development_dependency "combustion", "~> 0.5.1"
|
27
35
|
end
|
28
36
|
|
29
37
|
|
30
38
|
|
31
39
|
|
40
|
+
|
data/lib/fume.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "rails-i18n"
|
3
|
+
require "fume/version"
|
3
4
|
|
4
5
|
module Fume
|
5
|
-
VERSION = File.read(File.expand_path("../../VERSION", __FILE__)).chomp
|
6
|
-
|
7
6
|
extend ActiveSupport::Autoload
|
8
|
-
autoload :
|
9
|
-
autoload :
|
7
|
+
autoload :HelperExts
|
8
|
+
autoload :ActiveRecordExts
|
9
|
+
autoload :ControllerExts
|
10
|
+
|
10
11
|
autoload :RenderCache
|
12
|
+
autoload :RequireAccessor
|
11
13
|
|
12
14
|
def self.load_tasks
|
13
15
|
Dir[File.expand_path("../tasks/*.rake", __FILE__)].each { |ext| load ext }
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
require File.expand_path("../fume/railtie", __FILE__)
|
19
|
+
require File.expand_path("../fume/railtie", __FILE__)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fume
|
2
|
+
module ControllerExts
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :public_path, :public_url
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
def redirect_to_ok_url_or_default(default)
|
11
|
+
redirect_to params[:ok_url] || default
|
12
|
+
end
|
13
|
+
|
14
|
+
def public_url(source)
|
15
|
+
if source.include?("://")
|
16
|
+
source
|
17
|
+
else
|
18
|
+
"#{request.protocol}#{request.host_with_port}#{public_path(source)}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def public_path(source)
|
23
|
+
url = url_for(source)
|
24
|
+
return url if url.include?("://")
|
25
|
+
|
26
|
+
if url.start_with?(request.script_name)
|
27
|
+
url
|
28
|
+
else
|
29
|
+
"#{request.script_name}#{url}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/fume/railtie.rb
CHANGED
@@ -2,18 +2,16 @@ require "rails/railtie"
|
|
2
2
|
|
3
3
|
module Fume
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
|
-
initializer 'fume
|
6
|
-
|
5
|
+
initializer 'fume' do |app|
|
6
|
+
ActiveSupport.on_load(:action_controller) { include ControllerExts }
|
7
|
+
ActiveSupport.on_load(:action_view) { include HelperExts }
|
8
|
+
ActiveSupport.on_load(:active_record) { include ActiveRecordExts }
|
9
|
+
|
7
10
|
RenderCache.init!
|
8
11
|
end
|
9
12
|
|
10
|
-
initializer "fume.after_initialize", :after => :after_initialize do |app|
|
11
|
-
AppSettingLoader.init!
|
12
|
-
end
|
13
|
-
|
14
13
|
rake_tasks do
|
15
14
|
Fume.load_tasks
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
data/lib/fume/render_cache.rb
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
module Fume
|
2
2
|
module RenderCache
|
3
|
-
|
4
3
|
def self.init!
|
5
|
-
if defined? ::ActionController::Base
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
if defined? ::ActiveRecord::Base
|
10
|
-
::ActiveRecord::Base.send :include, ActiveRecordExtensions
|
11
|
-
end
|
4
|
+
::ActionController::Base.send :include, ControllerExtensions if defined? ::ActionController::Base
|
5
|
+
::ActiveRecord::Base.send :include, ActiveRecordExtensions if defined? ::ActiveRecord::Base
|
12
6
|
end
|
13
7
|
|
14
8
|
module ActiveRecordExtensions
|
@@ -38,12 +32,12 @@ module Fume
|
|
38
32
|
params[:key] = build_render_cache_key(key)
|
39
33
|
params[:options] = options
|
40
34
|
|
41
|
-
if
|
35
|
+
if page = RenderCachePage.load(params[:cache].read(params[:key]))
|
42
36
|
params[:key] = nil
|
43
37
|
|
44
|
-
response.charset =
|
45
|
-
response.content_type =
|
46
|
-
self.response_body =
|
38
|
+
response.charset = page.charset
|
39
|
+
response.content_type = page.content_type
|
40
|
+
self.response_body = page.body.html_safe
|
47
41
|
return
|
48
42
|
end
|
49
43
|
end
|
@@ -66,7 +60,7 @@ module Fume
|
|
66
60
|
when Array
|
67
61
|
obj.map { |val| self.key_to_string(val) }.join(",")
|
68
62
|
when Time, Date
|
69
|
-
obj.
|
63
|
+
obj.utc.iso8601
|
70
64
|
else
|
71
65
|
obj.to_s
|
72
66
|
end
|
@@ -74,26 +68,38 @@ module Fume
|
|
74
68
|
end
|
75
69
|
|
76
70
|
class RenderCacheFilter
|
77
|
-
def
|
71
|
+
def around(controller)
|
78
72
|
controller.render_cache_params ||= {
|
79
73
|
options: {},
|
80
74
|
cache: nil
|
81
75
|
}
|
76
|
+
|
82
77
|
controller.render_cache_params[:cache] = Rails.cache if controller.class.perform_caching
|
83
78
|
|
84
79
|
yield
|
85
80
|
|
86
81
|
params = controller.render_cache_params
|
87
82
|
if params[:key]
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
params[:cache].write(params[:key], content, params[:options])
|
83
|
+
page = RenderCachePage.new(controller.response.charset,
|
84
|
+
controller.response.content_type,
|
85
|
+
controller.response_body.is_a?(Array) ? controller.response_body.join : controller.response_body)
|
86
|
+
params[:cache].write(params[:key], page.dump, params[:options])
|
94
87
|
end
|
95
88
|
end
|
96
89
|
end
|
97
90
|
|
91
|
+
class RenderCachePage < Struct.new(:charset, :content_type, :body)
|
92
|
+
def self.load(io)
|
93
|
+
page = YAML.load(io) if io
|
94
|
+
page if page.is_a?(self)
|
95
|
+
rescue Exception
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
99
|
+
def dump
|
100
|
+
YAML.dump(self)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
98
104
|
end
|
99
105
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fume
|
2
|
+
module RequireAccessor
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def require_accessor(*names)
|
7
|
+
names.each do |name|
|
8
|
+
field_name = "#{name}_required"
|
9
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
10
|
+
def require_#{name}!
|
11
|
+
@#{field_name} = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def #{field_name}?
|
15
|
+
!!@#{field_name}
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/fume/version.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Fume::ControllerExts, type: :controller do
|
4
|
+
controller(ApplicationController) { }
|
5
|
+
|
6
|
+
describe "#public_path" do
|
7
|
+
before { request.script_name = "/context" }
|
8
|
+
subject { controller.send(:public_path, source) }
|
9
|
+
|
10
|
+
context "then source is full url" do
|
11
|
+
let(:source) { "http://test.host/path" }
|
12
|
+
it { should eq source }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "then source is path" do
|
16
|
+
let(:source) { "/path" }
|
17
|
+
it { should eq "/context/path" }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "then source already include script_name" do
|
21
|
+
let(:source) { "/context/path" }
|
22
|
+
it { should eq "/context/path" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#public_url" do
|
27
|
+
before { request.script_name = "/context" }
|
28
|
+
subject { controller.send(:public_url, source) }
|
29
|
+
|
30
|
+
context "then source is full url" do
|
31
|
+
let(:source) { "http://test.host/path" }
|
32
|
+
it { should eq source }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "then source is path" do
|
36
|
+
let(:source) { "/path" }
|
37
|
+
it { should eq "http://test.host/context/path" }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#redirect_to_ok_url_or_default" do
|
42
|
+
controller do
|
43
|
+
def create
|
44
|
+
redirect_to_ok_url_or_default "/foo"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:params) { Hash.new }
|
49
|
+
before { post :create, params }
|
50
|
+
|
51
|
+
context "then no ok_url" do
|
52
|
+
it { should redirect_to("/foo") }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "then have ok_url" do
|
56
|
+
let(:params) { { ok_url: "/bar" } }
|
57
|
+
it { should redirect_to("/bar") }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Fume::HelperExts, type: :helper do
|
4
|
+
describe "#ok_url_tag" do
|
5
|
+
subject { helper.ok_url_tag }
|
6
|
+
|
7
|
+
context "then not ok_url params" do
|
8
|
+
it { should eq nil }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "then have ok_url" do
|
12
|
+
before { params[:ok_url] = "/foo" }
|
13
|
+
it { should include 'value="/foo"' }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Fume::RenderCache::ActiveRecordExtensions, type: :model do
|
4
|
+
describe "#last_updated_at" do
|
5
|
+
let!(:pages) { 10.times.map { Page.create } }
|
6
|
+
it { expect(Page.last_updated_at).to eq pages[-1].reload.updated_at }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe Fume::RenderCache::ControllerExtensions, type: :controller do
|
12
|
+
controller(ApplicationController) do
|
13
|
+
def show
|
14
|
+
render_cache("key", {}) do
|
15
|
+
render text: "foo"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#render_cache" do
|
21
|
+
before { Rails.cache.clear }
|
22
|
+
before { controller.class.perform_caching = true }
|
23
|
+
after { controller.class.perform_caching = false }
|
24
|
+
|
25
|
+
let(:cache_key) { controller.send(:build_render_cache_key, "key") }
|
26
|
+
action { get :show, id: 1 }
|
27
|
+
it { expect(Rails.cache).to be_exist(cache_key) }
|
28
|
+
|
29
|
+
context "then page already cached" do
|
30
|
+
let(:cache_key) { "CACHE_KEY" }
|
31
|
+
before { allow(controller).to receive(:build_render_cache_key).and_return(cache_key) }
|
32
|
+
|
33
|
+
let(:cache_page) { Fume::RenderCache::RenderCachePage.new("utf8", "application/json", "bar") }
|
34
|
+
before { Rails.cache.write(cache_key, cache_page.dump) }
|
35
|
+
it { expect(response.body).to eq "bar" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#key_to_string" do
|
40
|
+
subject { controller.send(:key_to_string, obj) }
|
41
|
+
|
42
|
+
context "obj is nil" do
|
43
|
+
let(:obj) { nil }
|
44
|
+
it { should eq "nil!" }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "obj is array" do
|
48
|
+
let(:obj) { [ 1, 2 ] }
|
49
|
+
it { should eq "1,2" }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "obj is hash" do
|
53
|
+
let(:obj) { { a: 1, b: 2 } }
|
54
|
+
it { should eq "a=1&b=2" }
|
55
|
+
end
|
56
|
+
|
57
|
+
context "obj is time" do
|
58
|
+
let(:obj) { Time.parse("2014-03-21T04:28:12+0000") }
|
59
|
+
it { should eq "2014-03-21T04:28:12Z" }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Fume::RequireAccessor, type: :model do
|
4
|
+
class Page < ActiveRecord::Base
|
5
|
+
require_accessor :something
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { Page.new }
|
9
|
+
|
10
|
+
context 'default value' do
|
11
|
+
its(:something_required?) { should eq false }
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#require_something!' do
|
15
|
+
before { subject.require_something! }
|
16
|
+
its(:something_required?) { should eq true }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
require "simplecov"
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
# SimpleCov.start
|
4
6
|
|
5
|
-
require
|
6
|
-
|
7
|
+
require 'combustion'
|
8
|
+
Combustion.initialize! :all
|
9
|
+
require 'rspec/rails'
|
10
|
+
require "rspec-do_action"
|
7
11
|
|
8
|
-
|
12
|
+
require "fume"
|
13
|
+
require "pry-nav"
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
config.filter_run :focus
|
19
|
+
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = 'random'
|
25
|
+
config.before(:all) { FileUtils.mkdir_p File.expand_path("../../tmp/cache", __FILE__) } # ensure tmp/cache exists
|
12
26
|
end
|
metadata
CHANGED
@@ -1,102 +1,210 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fume
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- sunteya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails-i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.7.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.7.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.14.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.14.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-do_action
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.0.3
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-nav
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: combustion
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.5.1
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.5.1
|
167
|
+
description: some simple rails extentions.
|
70
168
|
email:
|
71
|
-
-
|
169
|
+
- sunteya@gmail.com
|
72
170
|
executables: []
|
73
171
|
extensions: []
|
74
172
|
extra_rdoc_files: []
|
75
173
|
files:
|
76
|
-
- .gitignore
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- ".travis.yml"
|
77
177
|
- CHANGELOG.md
|
78
178
|
- Gemfile
|
179
|
+
- LICENSE.txt
|
79
180
|
- README.md
|
80
181
|
- Rakefile
|
81
|
-
- VERSION
|
82
182
|
- fume.gemspec
|
183
|
+
- gemfiles/rails3_2.gemfile
|
83
184
|
- lib/fume.rb
|
84
|
-
- lib/fume/
|
85
|
-
- lib/fume/
|
185
|
+
- lib/fume/active_record_exts.rb
|
186
|
+
- lib/fume/controller_exts.rb
|
187
|
+
- lib/fume/helper_exts.rb
|
86
188
|
- lib/fume/railtie.rb
|
87
189
|
- lib/fume/render_cache.rb
|
88
|
-
- lib/
|
89
|
-
- lib/
|
90
|
-
- lib/generators/fume/simple_scaffold/templates/_form.html.erb
|
91
|
-
- lib/generators/fume/simple_scaffold/templates/controller.rb
|
92
|
-
- lib/generators/fume/simple_scaffold/templates/edit.html.erb
|
93
|
-
- lib/generators/fume/simple_scaffold/templates/index.html.erb
|
94
|
-
- lib/generators/fume/simple_scaffold/templates/new.html.erb
|
190
|
+
- lib/fume/require_accessor.rb
|
191
|
+
- lib/fume/version.rb
|
95
192
|
- lib/tasks/cache.rake
|
96
|
-
- spec/
|
193
|
+
- spec/fume/controller_exts_spec.rb
|
194
|
+
- spec/fume/helper_exts_spec.rb
|
195
|
+
- spec/fume/render_cache_spec.rb
|
196
|
+
- spec/fume/require_accessor_spec.rb
|
197
|
+
- spec/internal/app/controllers/application_controller.rb
|
198
|
+
- spec/internal/app/models/page.rb
|
199
|
+
- spec/internal/config/database.yml
|
200
|
+
- spec/internal/config/routes.rb
|
201
|
+
- spec/internal/db/schema.rb
|
202
|
+
- spec/internal/log/.gitignore
|
203
|
+
- spec/internal/public/favicon.ico
|
97
204
|
- spec/spec_helper.rb
|
98
|
-
homepage:
|
99
|
-
licenses:
|
205
|
+
homepage: https://github.com/sunteya/fume
|
206
|
+
licenses:
|
207
|
+
- MIT
|
100
208
|
metadata: {}
|
101
209
|
post_install_message:
|
102
210
|
rdoc_options: []
|
@@ -104,20 +212,30 @@ require_paths:
|
|
104
212
|
- lib
|
105
213
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
214
|
requirements:
|
107
|
-
- -
|
215
|
+
- - ">="
|
108
216
|
- !ruby/object:Gem::Version
|
109
217
|
version: '0'
|
110
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
219
|
requirements:
|
112
|
-
- -
|
220
|
+
- - ">="
|
113
221
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
222
|
+
version: '0'
|
115
223
|
requirements: []
|
116
224
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.0
|
225
|
+
rubygems_version: 2.2.0
|
118
226
|
signing_key:
|
119
227
|
specification_version: 4
|
120
|
-
summary:
|
228
|
+
summary: some simple rails extentions.
|
121
229
|
test_files:
|
122
|
-
- spec/
|
230
|
+
- spec/fume/controller_exts_spec.rb
|
231
|
+
- spec/fume/helper_exts_spec.rb
|
232
|
+
- spec/fume/render_cache_spec.rb
|
233
|
+
- spec/fume/require_accessor_spec.rb
|
234
|
+
- spec/internal/app/controllers/application_controller.rb
|
235
|
+
- spec/internal/app/models/page.rb
|
236
|
+
- spec/internal/config/database.yml
|
237
|
+
- spec/internal/config/routes.rb
|
238
|
+
- spec/internal/db/schema.rb
|
239
|
+
- spec/internal/log/.gitignore
|
240
|
+
- spec/internal/public/favicon.ico
|
123
241
|
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.10.0a
|
data/lib/fume/rails_ext.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module Fume
|
2
|
-
module RailsExt
|
3
|
-
|
4
|
-
def self.init!
|
5
|
-
if defined? ::ActionController::Base
|
6
|
-
::ActionController::Base.send :include, ControllerExtensions
|
7
|
-
end
|
8
|
-
|
9
|
-
if defined? ::ActionView::Base
|
10
|
-
::ActionView::Base.send :include, HelperExtensions
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module HelperExtensions
|
15
|
-
def ok_url_tag
|
16
|
-
hidden_field_tag "ok_url", params[:ok_url] if !params[:ok_url].blank?
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module ControllerExtensions
|
21
|
-
extend ActiveSupport::Concern
|
22
|
-
|
23
|
-
included do
|
24
|
-
helper_method :public_path, :public_url
|
25
|
-
end
|
26
|
-
|
27
|
-
module ClassMethods
|
28
|
-
def action_attr_accessor(*args)
|
29
|
-
options = args.extract_options!
|
30
|
-
[ args ].flatten.compact.each do |sym|
|
31
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
32
|
-
def self.#{sym}(obj)
|
33
|
-
before_filter { |c| c.send(:#{sym}=, obj) }
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_accessor :#{sym}
|
37
|
-
helper_method :#{sym}, :#{sym}=
|
38
|
-
EOS
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
def redirect_to_ok_url_or_default(default)
|
45
|
-
redirect_to params[:ok_url] || default
|
46
|
-
end
|
47
|
-
|
48
|
-
def public_url(source)
|
49
|
-
if source.include?("://")
|
50
|
-
source
|
51
|
-
else
|
52
|
-
"#{request.protocol}#{request.host_with_port}#{public_path(source)}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def public_path(source)
|
57
|
-
url = url_for(source)
|
58
|
-
return url if url.include?("://")
|
59
|
-
|
60
|
-
if url.start_with?(request.script_name)
|
61
|
-
url
|
62
|
-
else
|
63
|
-
"#{request.script_name}#{url}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Fume
|
2
|
-
|
3
|
-
class SimpleScaffoldGenerator < Rails::Generators::NamedBase
|
4
|
-
include Rails::Generators::ResourceHelpers
|
5
|
-
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
|
7
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
8
|
-
|
9
|
-
def create_controller_files
|
10
|
-
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
11
|
-
end
|
12
|
-
|
13
|
-
def copy_view_files
|
14
|
-
%w(index new _form edit).each do |view|
|
15
|
-
filename = "#{view}.html.erb"
|
16
|
-
template filename, File.join("app/views", controller_file_path, filename)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
# model
|
22
|
-
def plural_model_name
|
23
|
-
singular_model_name.pluralize
|
24
|
-
end
|
25
|
-
|
26
|
-
def singular_model_name
|
27
|
-
model_class_name.underscore
|
28
|
-
end
|
29
|
-
|
30
|
-
def model_class_name
|
31
|
-
@model_class_name ||= file_name.camelize
|
32
|
-
end
|
33
|
-
|
34
|
-
# path
|
35
|
-
def resources_path_prefix
|
36
|
-
(class_path + [plural_model_name]).join('_')
|
37
|
-
end
|
38
|
-
|
39
|
-
def resource_path_prefix
|
40
|
-
(class_path + [singular_model_name]).join('_')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
-
|
3
|
-
def index
|
4
|
-
@search = <%= "#{model_class_name}.search(params[:search])" %>
|
5
|
-
<%= "@#{plural_model_name}" %> = @search.page(params[:page])
|
6
|
-
end
|
7
|
-
|
8
|
-
def new
|
9
|
-
<%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.new" %>
|
10
|
-
end
|
11
|
-
|
12
|
-
def create
|
13
|
-
<%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.new(params[:#{singular_model_name}])" %>
|
14
|
-
|
15
|
-
if <%= "@#{singular_model_name}.save" %>
|
16
|
-
flash[:notice] = '<%= human_name %> was successfully created.'
|
17
|
-
redirect_to_ok_url_or_default :action => "index"
|
18
|
-
else
|
19
|
-
render :action => "new"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def edit
|
24
|
-
@<%= singular_model_name %> = <%= "#{model_class_name}.find(params[:id])" %>
|
25
|
-
end
|
26
|
-
|
27
|
-
def update
|
28
|
-
<%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.find(params[:id])" %>
|
29
|
-
|
30
|
-
if <%= "@#{singular_model_name}.update_attributes(params[:#{singular_model_name}])" %>
|
31
|
-
flash[:notice] = '<%= human_name %> was successfully updated.'
|
32
|
-
redirect_to_ok_url_or_default :action => "index"
|
33
|
-
else
|
34
|
-
render :action => "edit"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def destroy
|
39
|
-
<%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.find_by_id(params[:id])" %>
|
40
|
-
<%= "@#{singular_model_name}.destroy" %> if @<%= singular_model_name %>
|
41
|
-
|
42
|
-
redirect_to_ok_url_or_default :action => "index"
|
43
|
-
end
|
44
|
-
end
|
@@ -1,5 +0,0 @@
|
|
1
|
-
<h1>Editing <%%= <%= "#{model_class_name}.human_name" %> %></h1>
|
2
|
-
|
3
|
-
<%%= semantic_form_for(<%= "@#{singular_model_name}" %>, :url => <%= resource_path_prefix %>_path(<%= "@#{singular_model_name}" %>)) do |f| %>
|
4
|
-
<%%= render :partial => "form", :locals => { :f => f } %>
|
5
|
-
<%% end %>
|
@@ -1,32 +0,0 @@
|
|
1
|
-
<h1>Listing <%%= <%= "#{model_class_name}.human_name" %> %></h1>
|
2
|
-
|
3
|
-
<table>
|
4
|
-
<thead>
|
5
|
-
<tr>
|
6
|
-
<th><%%= sort_link @search, :id %></th>
|
7
|
-
<%- for attribute in attributes -%>
|
8
|
-
<th><%%= sort_link @search, :<%= attribute.name %> %></th>
|
9
|
-
<%- end -%>
|
10
|
-
<th>Actions</th>
|
11
|
-
</tr>
|
12
|
-
</thead>
|
13
|
-
|
14
|
-
<%% <%= "@#{plural_model_name}" %>.each do |<%= singular_model_name %>| %>
|
15
|
-
<tr>
|
16
|
-
<td><%%= <%= singular_model_name %>.id %></td>
|
17
|
-
<%- for attribute in attributes -%>
|
18
|
-
<td><%%=<%= "l" if %w[date datetime time].include?(attribute.type.to_s) %> <%= singular_model_name %>.<%= attribute.name %> %></td>
|
19
|
-
<%- end -%>
|
20
|
-
<td>
|
21
|
-
<%%= link_to 'Edit', edit_<%= resource_path_prefix %>_path(<%= singular_model_name %>) %>
|
22
|
-
<%%= link_to 'Destroy', <%= resource_path_prefix %>_path(<%= singular_model_name %>), :confirm => 'Are you sure?', :method => :delete %>
|
23
|
-
</td>
|
24
|
-
</tr>
|
25
|
-
<%% end %>
|
26
|
-
</table>
|
27
|
-
|
28
|
-
<%%= paginate <%= "@#{plural_model_name}" %> %>
|
29
|
-
|
30
|
-
<div class="actions">
|
31
|
-
<%%= link_to 'New <%= human_name %>', new_<%= resource_path_prefix %>_path %>
|
32
|
-
</div>
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|