neuron 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,9 +12,20 @@ module Neuron
12
12
  end
13
13
  end
14
14
 
15
- def access_denied(exception = nil)
16
- redirect_to '/422.html'
15
+ if defined?(::Devise)
16
+ def access_denied(exception = nil)
17
+ if user_signed_in?
18
+ redirect_to '/422.html'
19
+ else
20
+ redirect_to new_user_session_path, alert: I18n.t('devise.failure.unauthenticated')
21
+ end
22
+ end
23
+ else
24
+ def access_denied(exception = nil)
25
+ redirect_to '/422.html'
26
+ end
17
27
  end
28
+
18
29
  end
19
30
 
20
31
  module View
@@ -5,6 +5,17 @@ module Neuron
5
5
  module Controller
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ def self.setup!
9
+ if defined?(::ActionController)
10
+ ActionController::Base.send(:include, Neuron::Controller)
11
+ if defined?(::InheritedResources)
12
+ ActionController::Base.send(:include, Neuron::Resources::Controller)
13
+ require 'neuron/integrations/cancan_inherited_resources' if defined?(::CanCan)
14
+ end
15
+ ActionController::Base.send(:include, Neuron::Authorization::Controller) if defined?(::CanCan)
16
+ end
17
+ end
18
+
8
19
  module ClassMethods
9
20
  def append_neuron_view_path_resolver
10
21
  append_view_path Neuron::Resolver.new
@@ -0,0 +1,11 @@
1
+ require 'neuron'
2
+ require 'rails'
3
+ require 'rails/engine'
4
+
5
+ class Neuron::Railtie < Rails::Engine
6
+ config.app_generators.stylesheets false
7
+
8
+ config.to_prepare do
9
+ Neuron.setup!
10
+ end
11
+ end
@@ -48,6 +48,7 @@ module Neuron
48
48
  options[:class] ||= resource_class
49
49
  options[:by] = options[:by].to_sym
50
50
  options[:as] ||= human(options[:class], options[:by])
51
+ html_options[:title] ||= human(options[:class], options[:by])
51
52
  asc_orders = Array(params[:ascending]).map(&:to_sym)
52
53
  desc_orders = Array(params[:descending]).map(&:to_sym)
53
54
  ascending = asc_orders.include?(options[:by])
@@ -107,7 +108,7 @@ module Neuron
107
108
  collection ||= self.collection
108
109
  content_tag(:article, class: 'b-collection') do
109
110
  ''.html_safe.tap do |result|
110
- result << content_tag(:header, collection_title(collection, tag), class: 'b-collection__header')
111
+ result << content_tag(:header, collection_title(collection, tag: tag), class: 'b-collection__header')
111
112
  if block_given?
112
113
  result << capture(&block)
113
114
  else
@@ -130,7 +131,7 @@ module Neuron
130
131
  result << title(nil,
131
132
  resource: link_to(resource, canonical_path(resource)),
132
133
  default: resource.to_s)
133
- if (action == :show) && can?(:update, resource)
134
+ if (action == :show) && can?(:update, resource) && controller.respond_to?(:edit)
134
135
  result << content_tag(:sup,
135
136
  link_to(t(:edit,
136
137
  object: resource,
@@ -0,0 +1,27 @@
1
+ require 'neuron/show_for'
2
+ require 'show_for/helper'
3
+
4
+ module Neuron
5
+ module ShowFor
6
+ module Helper
7
+ # Creates a div around the object and yields a builder.
8
+ #
9
+ # @example
10
+ # show_for @user do |f|
11
+ # f.attribute :name
12
+ # f.attribute :email
13
+ # end
14
+ def show_for(object, html_options={}, &block)
15
+ tag = html_options.delete(:show_for_tag) || ::ShowFor.show_for_tag
16
+
17
+ html_options[:id] ||= dom_id(object, :show_for)
18
+ html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".strip
19
+
20
+ builder = html_options.delete(:builder) || ::ShowFor::Builder
21
+ content = capture(builder.new(object, self), &block)
22
+
23
+ content_tag(tag, content, html_options)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'neuron'
2
+ require 'show_for'
3
+
4
+ module Neuron
5
+ module ShowFor
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :Helper
9
+
10
+ def self.setup!
11
+ # Reconfigure ShowFor
12
+ ShowFor.wrapper_tag = :dl
13
+ ShowFor.label_tag = :dt
14
+ ShowFor.content_tag = :dd
15
+ ShowFor.separator = ''
16
+
17
+ Helper # loads improved ShowFor helper
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Neuron
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/neuron/view.rb CHANGED
@@ -2,6 +2,18 @@ require 'neuron'
2
2
 
3
3
  module Neuron
4
4
  module View
5
+ extend ActiveSupport::Memoizable
6
+
7
+ def self.setup!
8
+ if defined?(::ActionView)
9
+ ActionView::Base.send(:include, Neuron::View)
10
+ ActionView::Base.send(:include, Neuron::Navigation::View)
11
+ ActionView::Base.send(:include, Neuron::Resources::View) if defined?(::InheritedResources)
12
+ ActionView::Base.send(:include, Neuron::Authorization::View) if defined?(::CanCan)
13
+ ActionView::Base.send(:include, Neuron::ShowFor::Helper) if defined?(::ShowFor)
14
+ end
15
+ end
16
+
5
17
  def block_modifiers(block, *modifiers)
6
18
  klasses = [block]
7
19
  if (options = modifiers.extract_options!).any?
@@ -28,24 +40,26 @@ module Neuron
28
40
  def human(klass, attribute = nil)
29
41
  attribute ? klass.human_attribute_name(attribute) : klass.name.human
30
42
  end
31
-
32
- # Build canonical path for given resource
33
- def canonical_path(resource, options = {})
34
- canonical_url(resource, options.merge(routing_type: :path))
35
- end
43
+ memoize :human
36
44
 
37
45
  # Build canonical url for given resource
38
46
  def canonical_url(resource, options = {})
39
47
  polymorphic_url(resource, options)
40
48
  end
41
49
 
50
+ # Build canonical path for given resource
51
+ def canonical_path(resource, options = {})
52
+ canonical_url(resource, options.merge(routing_type: :path))
53
+ end
54
+
42
55
  def view_name
43
56
  {create: 'new', update: 'edit'}[action_name] || action_name
44
57
  end
45
58
 
46
59
  def controller_i18n_scope
47
- @controller_i18n_scope ||= controller.controller_path.gsub(%r{/}, '.')
60
+ controller.controller_path.gsub(%r{/}, '.')
48
61
  end
62
+ memoize :controller_i18n_scope
49
63
 
50
64
  def time(time, options = {})
51
65
  format = options.delete(:format) { :short }
data/lib/neuron.rb CHANGED
@@ -5,35 +5,22 @@ module Neuron
5
5
  autoload :Authorization, 'neuron/authorization'
6
6
  autoload :Controller, 'neuron/controller'
7
7
  autoload :Navigation, 'neuron/navigation'
8
+ autoload :Railtie, 'neuron/railtie'
8
9
  autoload :Resolver, 'neuron/resolver'
9
10
  autoload :Resources, 'neuron/resources'
10
- autoload :Railtie, 'neuron/rails'
11
+ autoload :ShowFor, 'neuron/show_for'
11
12
  autoload :View, 'neuron/view'
12
13
 
13
- def self.setup!
14
- if defined?(ActionView)
15
- ActionView::Base.send :include, Neuron::View
16
- ActionView::Base.send :include, Neuron::Navigation::View
14
+ class << self
15
+ def setup!
16
+ Neuron::Controller.setup!
17
+ Neuron::View.setup!
17
18
  end
18
- if defined?(ActionController)
19
- ActionController::Base.send :include, Neuron::Controller
20
- end
21
- if defined?(InheritedResources)
22
- ActionController::Base.send :include, Neuron::Resources::Controller
23
- ActionView::Base.send :include, Neuron::Resources::View
24
- if defined?(CanCan)
25
- require 'neuron/integrations/cancan_inherited_resources'
26
- end
27
- end
28
- if defined?(CanCan)
29
- ActionController::Base.send :include, Neuron::Authorization::Controller
30
- ActionView::Base.send :include, Neuron::Authorization::View
31
- end
32
- end
33
19
 
34
- def self.path
35
- File.expand_path('../..', __FILE__)
20
+ def path
21
+ File.expand_path('../..', __FILE__)
22
+ end
36
23
  end
37
24
  end
38
25
 
39
- require 'neuron/rails' if defined?(Rails)
26
+ require 'neuron/railtie' if defined?(Rails)
data/neuron.gemspec CHANGED
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'rake'
21
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neuron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-04 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2011-06-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &73648720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *73648720
14
25
  description: Code reused in many applications
15
26
  email:
16
27
  - al@semyonov.us
@@ -36,9 +47,11 @@ files:
36
47
  - lib/neuron/controller.rb
37
48
  - lib/neuron/integrations/cancan_inherited_resources.rb
38
49
  - lib/neuron/navigation.rb
39
- - lib/neuron/rails.rb
50
+ - lib/neuron/railtie.rb
40
51
  - lib/neuron/resolver.rb
41
52
  - lib/neuron/resources.rb
53
+ - lib/neuron/show_for.rb
54
+ - lib/neuron/show_for/helper.rb
42
55
  - lib/neuron/version.rb
43
56
  - lib/neuron/view.rb
44
57
  - neuron.gemspec
@@ -54,12 +67,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
67
  - - ! '>='
55
68
  - !ruby/object:Gem::Version
56
69
  version: '0'
70
+ segments:
71
+ - 0
72
+ hash: -188768273
57
73
  required_rubygems_version: !ruby/object:Gem::Requirement
58
74
  none: false
59
75
  requirements:
60
76
  - - ! '>='
61
77
  - !ruby/object:Gem::Version
62
78
  version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -188768273
63
82
  requirements: []
64
83
  rubyforge_project: neuron
65
84
  rubygems_version: 1.8.5
data/lib/neuron/rails.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'neuron'
2
- require 'rails'
3
-
4
- module Neuron
5
- class Railtie < Rails::Engine
6
- config.to_prepare do
7
- Neuron.setup!
8
- end
9
- end
10
- end