fume 0.8.1a → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
-
1
+ ## 0.9.0
2
+ - extract cancan to standalone gem
3
+ - remove authlogic ext
2
4
 
3
5
  ## 0.8.0
4
6
  - don't depends all rails plugin, you must depend it for yourself.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1a
1
+ 0.9.0
data/fume.gemspec CHANGED
@@ -18,23 +18,9 @@ Gem::Specification.new do |s|
18
18
 
19
19
 
20
20
  # rails
21
- s.add_runtime_dependency "rails", "~> 3.2.1"
22
- s.add_runtime_dependency "rails-i18n", "~> 0.3.0"
23
-
24
- # require library
25
- s.add_runtime_dependency "hashie", ">= 1.2.0"
26
-
27
- # library
28
- # s.add_runtime_dependency "timeliness", "~> 0.3.4"
29
- # s.add_runtime_dependency "addressable", "~> 2.2.6"
30
-
31
- # rails plugin
32
- # s.add_runtime_dependency "authlogic", "~> 3.0.3"
33
- # s.add_runtime_dependency "formtastic", "~> 1.2.4"
34
- # s.add_runtime_dependency "cancan", "~> 1.6.5"
35
- # s.add_runtime_dependency "symbolize", "~> 3.2.0"
36
- # s.add_runtime_dependency "meta_search", "~> 1.0.6"
37
- # s.add_runtime_dependency "kaminari", "~> 0.12.4"
21
+ s.add_dependency "rails", "~> 3.2.7"
22
+ s.add_dependency "rails-i18n", "~> 0.6.5"
23
+ s.add_dependency "hashie", ">= 1.2.0"
38
24
 
39
25
  # development
40
26
  s.add_development_dependency "version"
data/lib/fume.rb CHANGED
@@ -1,24 +1,18 @@
1
1
  require "active_support"
2
- require File.expand_path("../fume/railtie", __FILE__)
3
-
4
- # 3rd gems
5
2
  require "rails-i18n"
6
3
 
7
-
8
4
  module Fume
9
- extend ActiveSupport::Autoload
5
+ VERSION = File.read(File.expand_path("../../VERSION", __FILE__)).chomp
10
6
 
11
- autoload :Authlogic
7
+ extend ActiveSupport::Autoload
12
8
  autoload :RailsExt
13
- autoload :Cancan
14
9
  autoload :SimpleNav
15
10
  autoload :AppSettingLoader
16
11
  autoload :RenderCache
17
12
 
18
- VERSION = File.read(File.expand_path("../../VERSION", __FILE__)).chomp
19
-
20
13
  def self.load_tasks
21
14
  Dir[File.expand_path("../tasks/*.rake", __FILE__)].each { |ext| load ext }
22
15
  end
23
-
24
16
  end
17
+
18
+ require File.expand_path("../fume/railtie", __FILE__)
@@ -1,8 +1,7 @@
1
1
  module Fume
2
-
3
2
  class AppSettingLoader
4
-
5
- def self.try_enable(app)
3
+
4
+ def self.init!
6
5
  %w[application.extra.rb application.local.rb].each do |config_filename|
7
6
  path = Rails.root.join("config", config_filename)
8
7
  require path if File.exists?(path)
@@ -1,22 +1,19 @@
1
1
  module Fume
2
2
  module RailsExt
3
- def self.try_enable(app)
4
- if defined? ::ActionController
5
- ActionController::Base.send :include, ControllerExtensions
3
+
4
+ def self.init!
5
+ if defined? ::ActionController::Base
6
+ ::ActionController::Base.send :include, ControllerExtensions
6
7
  end
7
8
 
8
- if defined? ::ActiveRecord
9
- ::ActiveRecord::Base.send :include, ActiveRecordExtensions
9
+ if defined? ::ActionView::Base
10
+ ::ActionView::Base.send :include, HelperExtensions
10
11
  end
11
12
  end
12
13
 
13
- module ActiveRecordExtensions
14
- extend ActiveSupport::Concern
15
-
16
- module ClassMethods
17
- def last_updated_at
18
- self.reorder("").select("MAX(#{self.table_name}.updated_at) AS updated_at").first.try(:updated_at)
19
- end
14
+ module HelperExtensions
15
+ def ok_url_tag
16
+ hidden_field_tag "ok_url", params[:ok_url] if !params[:ok_url].blank?
20
17
  end
21
18
  end
22
19
 
@@ -43,32 +40,31 @@ module Fume
43
40
  end
44
41
  end
45
42
 
46
- module InstanceMethods
47
-
48
- protected
49
- def redirect_to_ok_url_or_default(default)
50
- redirect_to params[:ok_url] || default
51
- end
52
-
53
- def public_url(source)
54
- if source.include?("://")
55
- source
56
- else
57
- request.protocol + request.host_with_port + public_path(source)
58
- end
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)}"
59
53
  end
54
+ end
60
55
 
61
- def public_path(source)
62
- if source.include?("://")
63
- source
64
- else
65
- url = url_for("#{source}")
66
- "#{request.script_name}#{url}"
67
- end
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}"
68
64
  end
69
65
  end
66
+
70
67
  end
71
-
72
68
  end
73
69
  end
74
70
 
data/lib/fume/railtie.rb CHANGED
@@ -3,13 +3,13 @@ require "rails/railtie"
3
3
  module Fume
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer 'fume.initialize', :after => :after_initialize do |app|
6
- Fume.constants.each do |name|
7
- ext_module = Fume.const_get(name)
8
-
9
- if ext_module.respond_to?(:try_enable)
10
- ext_module.try_enable(app)
11
- end
12
- end
6
+ RailsExt.init!
7
+ RenderCache.init!
8
+ SimpleNav.init!
9
+ end
10
+
11
+ initializer "fume.after_initialize", :after => :after_initialize do |app|
12
+ AppSettingLoader.init!
13
13
  end
14
14
 
15
15
  rake_tasks do
@@ -1,69 +1,81 @@
1
1
  module Fume
2
2
  module RenderCache
3
3
 
4
- def self.try_enable(app)
5
- if defined? ::ActionController
6
- ActionController::Base.send :include, ControllerExtensions
4
+ def self.init!
5
+ if defined? ::ActionController::Base
6
+ ::ActionController::Base.send :include, ControllerExtensions
7
+ end
8
+
9
+ if defined? ::ActiveRecord::Base
10
+ ::ActiveRecord::Base.send :include, ActiveRecordExtensions
11
+ end
12
+ end
13
+
14
+ module ActiveRecordExtensions
15
+ extend ::ActiveSupport::Concern
16
+
17
+ module ClassMethods
18
+ def last_updated_at
19
+ self.reorder("").select("MAX(#{self.table_name}.updated_at) AS updated_at").first.try(:updated_at)
20
+ end
7
21
  end
8
22
  end
9
23
 
10
24
  module ControllerExtensions
11
- extend ActiveSupport::Concern
25
+ extend ::ActiveSupport::Concern
12
26
 
13
27
  included do
14
28
  attr_accessor :render_cache_params
15
29
  around_filter RenderCacheFilter.new
16
30
  end
17
31
 
18
- module InstanceMethods
19
- protected
20
- def render_cache(key, options = {})
21
- if self.class.perform_caching
22
- key = build_render_cache_key(key)
23
- cache = Rails.cache
24
-
25
- fragment = cache.read(key)
26
- if fragment
27
- response.charset = fragment[:charset]
28
- response.content_type = fragment[:content_type]
29
- self.response_body = fragment[:body].html_safe
30
- else
31
- yield if block_given?
32
+ protected
33
+ def render_cache(key, options = {})
34
+ if self.class.perform_caching
35
+ key = build_render_cache_key(key)
36
+ cache = Rails.cache
32
37
 
33
- self.render_cache_params = {
34
- :key => key,
35
- :options => options,
36
- :cache => cache
37
- }
38
- end
38
+ fragment = cache.read(key)
39
+ if fragment
40
+ response.charset = fragment[:charset]
41
+ response.content_type = fragment[:content_type]
42
+ self.response_body = fragment[:body].html_safe
39
43
  else
40
44
  yield if block_given?
41
- end
42
45
 
46
+ self.render_cache_params = {
47
+ :key => key,
48
+ :options => options,
49
+ :cache => cache
50
+ }
51
+ end
52
+ else
53
+ yield if block_given?
43
54
  end
44
55
 
45
- def build_render_cache_key(key)
46
- base = "render@#{params[:controller]}/#{params[:action]}.#{params[:format]}"
47
- key = self.key_to_string(key)
48
- "#{base}##{key}"
49
- end
56
+ end
50
57
 
51
- def key_to_string(obj)
52
- case obj
53
- when nil
54
- "nil!"
55
- when Hash
56
- obj.keys.sort.map { |k| "#{k}=#{self.key_to_string(obj[k])}" }.join("&")
57
- when Array
58
- obj.map { |val| self.key_to_string(val) }.join(",")
59
- when Time, Date
60
- obj.to_s(:db)
61
- else
62
- obj.to_s
63
- end
64
- end
58
+ def build_render_cache_key(key)
59
+ base = "render@#{params[:controller]}/#{params[:action]}.#{params[:format]}"
60
+ key = self.key_to_string(key)
61
+ "#{base}##{key}"
62
+ end
65
63
 
64
+ def key_to_string(obj)
65
+ case obj
66
+ when nil
67
+ "nil!"
68
+ when Hash
69
+ obj.keys.sort.map { |k| "#{k}=#{self.key_to_string(obj[k])}" }.join("&")
70
+ when Array
71
+ obj.map { |val| self.key_to_string(val) }.join(",")
72
+ when Time, Date
73
+ obj.to_s(:db)
74
+ else
75
+ obj.to_s
76
+ end
66
77
  end
78
+
67
79
  end
68
80
 
69
81
  class RenderCacheFilter
@@ -3,8 +3,10 @@ require "hashie"
3
3
  module Fume
4
4
  module SimpleNav
5
5
 
6
- def self.try_enable(app)
7
- ActionView::Base.send :include, HelperExtensions
6
+ def self.init!
7
+ if defined? ::ActionView::Base
8
+ ::ActionView::Base.send :include, HelperExtensions
9
+ end
8
10
  end
9
11
 
10
12
  module HelperExtensions
metadata CHANGED
@@ -1,41 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fume
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1a
5
- prerelease: 5
4
+ version: 0.9.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sunteya
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-29 00:00:00.000000000Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70313373491960 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.1
21
+ version: 3.2.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70313373491960
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.7
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rails-i18n
27
- requirement: &70313373491460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: 0.3.0
37
+ version: 0.6.5
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70313373491460
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.5
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: hashie
38
- requirement: &70313373491000 !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: 1.2.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70313373491000
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: version
49
- requirement: &70313373490620 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70313373490620
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  description: a simple rails scaffold.
59
79
  email:
60
80
  - Sunteya@gmail.com
@@ -71,8 +91,6 @@ files:
71
91
  - fume.gemspec
72
92
  - lib/fume.rb
73
93
  - lib/fume/app_setting_loader.rb
74
- - lib/fume/authlogic.rb
75
- - lib/fume/cancan.rb
76
94
  - lib/fume/rails_ext.rb
77
95
  - lib/fume/railtie.rb
78
96
  - lib/fume/render_cache.rb
@@ -85,11 +103,6 @@ files:
85
103
  - lib/generators/fume/simple_scaffold/templates/index.html.erb
86
104
  - lib/generators/fume/simple_scaffold/templates/new.html.erb
87
105
  - lib/tasks/cache.rake
88
- - rails_generators/fume/fume_generator.rb
89
- - rails_generators/fume/rspec/rspec_gen.rb
90
- - rails_generators/fume/rspec/templates/spec/support/erb_macros.rb
91
- - rails_generators/fume/rspec/templates/spec/support/fume_controller_macros.rb
92
- - spec/fume/cancan_spec.rb
93
106
  - spec/spec.opts
94
107
  - spec/spec_helper.rb
95
108
  homepage: http://github.com/sunteya/fume
@@ -106,20 +119,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
119
  version: '0'
107
120
  segments:
108
121
  - 0
109
- hash: 19325340432934255
122
+ hash: -559507536724635748
110
123
  required_rubygems_version: !ruby/object:Gem::Requirement
111
124
  none: false
112
125
  requirements:
113
- - - ! '>'
126
+ - - ! '>='
114
127
  - !ruby/object:Gem::Version
115
- version: 1.3.1
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: -559507536724635748
116
132
  requirements: []
117
133
  rubyforge_project:
118
- rubygems_version: 1.8.10
134
+ rubygems_version: 1.8.24
119
135
  signing_key:
120
136
  specification_version: 3
121
137
  summary: a simple rails scaffold.
122
138
  test_files:
123
- - spec/fume/cancan_spec.rb
124
139
  - spec/spec.opts
125
140
  - spec/spec_helper.rb
@@ -1,34 +0,0 @@
1
- module Fume
2
- module Authlogic
3
- def self.try_enable(app)
4
- if defined? ::Authlogic
5
- ActionController::Base.send :include, ControllerExtensions
6
- end
7
- end
8
-
9
- module ControllerExtensions
10
- extend ActiveSupport::Concern
11
-
12
- included do
13
- helper_method :current_user_session, :current_user
14
- end
15
-
16
- module InstanceMethods
17
-
18
- protected
19
- def current_user_session
20
- return @current_user_session if defined?(@current_user_session)
21
- @current_user_session = UserSession.find
22
- end
23
-
24
- def current_user
25
- return @current_user if defined?(@current_user)
26
- @current_user = current_user_session && current_user_session.user
27
- end
28
-
29
- end
30
- end
31
- end
32
- end
33
-
34
-
data/lib/fume/cancan.rb DELETED
@@ -1,43 +0,0 @@
1
- module Fume
2
- module Cancan
3
- def self.try_enable(app)
4
- if defined? ::CanCan
5
- ActionController::Base.send :include, ControllerExtensions
6
- end
7
- end
8
-
9
- module ControllerExtensions
10
- extend ActiveSupport::Concern
11
-
12
- module ClassMethods
13
-
14
- def authorize_object(options = {})
15
- filter_options = options.slice(:only, :except) if options.is_a?(Hash)
16
- before_filter(filter_options || {}) do |controller|
17
- controller.send :authorize_object!, options
18
- end
19
- end
20
-
21
- end
22
-
23
- module InstanceMethods
24
-
25
- protected
26
- def authorize_object!(options)
27
- action = params[:action].to_sym
28
- case options
29
- when Hash
30
- authorize! action, options[:object]
31
- else
32
- authorize! action, options
33
- end
34
- end
35
-
36
- end
37
- end
38
-
39
- end
40
-
41
- end
42
-
43
-
@@ -1,55 +0,0 @@
1
- class FumeGenerator < Rails::Generator::Base
2
-
3
- attr_accessor :gen
4
- delegate :source_path, :destination_path, :manifest, :after_generate, :replay, :to => :gen
5
-
6
- def initialize(runtime_args, runtime_options = {})
7
- super
8
-
9
- usage if args.empty?
10
- gen_name = args.shift
11
-
12
- gen_path = File.join(spec.path, gen_name)
13
- gen_spec = Fume::Gen::Spec.new(gen_name, gen_path, gen_path)
14
-
15
- @gen = gen_spec.klass.new(runtime_args, runtime_options)
16
- end
17
- end
18
-
19
-
20
- module Fume
21
- module Gen
22
- class Base < Rails::Generator::Base
23
- def destination_root_pathname
24
- Pathname.new(self.destination_root)
25
- end
26
-
27
- def source_root_pathname
28
- Pathname.new(self.source_root)
29
- end
30
-
31
- def cp_files(m, pattern)
32
- Pathname.glob(source_root_pathname.join(pattern)) do |source_path|
33
- relative_path = source_path.relative_path_from(source_root_pathname)
34
- destination_path = destination_root_pathname.join(relative_path)
35
-
36
- if source_path.directory?
37
- m.directory relative_path unless destination_path.exist?
38
- else
39
- m.file relative_path.to_s, relative_path.to_s
40
- end
41
- end
42
- end
43
- end
44
-
45
- class Spec < Rails::Generator::Spec
46
- def class_file
47
- "#{path}/#{name}_gen.rb"
48
- end
49
-
50
- def class_name
51
- "#{name.camelize}Gen"
52
- end
53
- end
54
- end
55
- end
@@ -1,8 +0,0 @@
1
- class RspecGen < Fume::Gen::Base
2
-
3
- def manifest
4
- record do |m|
5
- cp_files m, File.join("**", "*")
6
- end
7
- end
8
- end
@@ -1,18 +0,0 @@
1
- module ErbMacros
2
- def self.included(base)
3
- base.send :extend, ClassMethods
4
- base.send :include, InstanceMethods
5
- end
6
-
7
- module ClassMethods
8
- end
9
-
10
- module InstanceMethods
11
- def render_template(template)
12
- erb = ERB.new(template.read)
13
- tmp_file = Tempfile.new("erb")
14
- File.open(tmp_file.path, "wb") { |f| f.write(erb.result(binding)) }
15
- tmp_file
16
- end
17
- end
18
- end
@@ -1,118 +0,0 @@
1
- module FumeControllerMacros
2
- def self.included(base)
3
- base.send :extend, ClassMethods
4
- base.send :include, InstanceMethods
5
- end
6
-
7
- module ClassMethods
8
-
9
- class ActionMethod < Struct.new(:method, :action)
10
- def to_proc
11
- eval <<-EOV
12
- Proc.new do |params|
13
- #{method} "#{action}", params
14
- end
15
- EOV
16
- end
17
- end
18
-
19
- %w{ get post put delete }.each do |name|
20
- define_method(name) do |*actions|
21
- [ actions ].flatten.map do |action|
22
- ActionMethod.new(name, action)
23
- end
24
- end
25
- end
26
-
27
-
28
- %w{ be_success be_redirect be_invalid }.each do |be_method|
29
- eval %Q[
30
- def it_should_#{be_method}_for(*args, &block)
31
- options = args.extract_options!() || {}
32
- action_methods = args.flatten
33
- action_methods.each do |action_method|
34
- it "should #{be_method} for \#{action_method.method} :\#{action_method.action} action \#{options[:message]}" do
35
- params = {}
36
- if block_given?
37
- result = self.instance_exec(&block)
38
- params = result if result.is_a? Hash
39
- end
40
-
41
- self.instance_exec(params, &action_method)
42
- response.should #{be_method}
43
- end
44
- end
45
- end
46
- ]
47
- end
48
-
49
-
50
- def it_should_be_like_restful_resources(options = {}, &block)
51
- actions = [ :index, :new, :create, :show, :edit, :update, :destroy ]
52
- actions &= [ options[:only] ].flatten if options[:only]
53
- actions -= [ options[:except] ].flatten if options[:except]
54
-
55
- if actions.include?(:index)
56
- it_should_be_success_for get(:index) do
57
- params = instance_exec(&block)
58
- end
59
- end
60
-
61
- if actions.include?(:show)
62
- it_should_be_success_for get(:show) do
63
- params = instance_exec(&block)
64
- end
65
- end
66
-
67
- if actions.include?(:new)
68
- it_should_be_success_for get(:new) do
69
- params = instance_exec(&block)
70
- end
71
- end
72
-
73
- if actions.include?(:create)
74
- it_should_be_redirect_for post(:create) do
75
- params = instance_exec(&block)
76
- params.merge(params.delete(:valid_attributes))
77
- end
78
-
79
- it_should_be_invalid_for post(:create) do
80
- params = instance_exec(&block)
81
- params.merge(params.delete(:invalid_attributes))
82
- end
83
- end
84
-
85
- if actions.include?(:edit)
86
- it_should_be_success_for get(:edit) do
87
- params = instance_exec(&block)
88
- end
89
- end
90
-
91
- if actions.include?(:update)
92
- it_should_be_redirect_for put(:update) do
93
- params = instance_exec(&block)
94
- params.merge(params.delete(:valid_attributes))
95
- end
96
-
97
- it_should_be_invalid_for put(:update) do
98
- params = instance_exec(&block)
99
- params.merge(params.delete(:invalid_attributes))
100
- end
101
- end
102
-
103
- if actions.include?(:destroy)
104
- it_should_be_redirect_for delete(:destroy) do
105
- params = instance_exec(&block)
106
- end
107
- end
108
- end
109
-
110
- end # ClassMethods
111
-
112
- module InstanceMethods
113
- def be_invalid(*args)
114
- be_success(*args)
115
- end
116
- end
117
-
118
- end
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fume::Cancan do
4
- before(:each) do
5
- Fume::Cancan.try_enable
6
- @controller_class = Class.new(ActionController::Base)
7
- end
8
-
9
- it "should add method to action controller base" do
10
- @controller_class.methods.should be_include "authorize_namespace"
11
- @controller_class.instance_methods.should be_include "authorize_namespace"
12
- end
13
- end