neuron 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neuron.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,30 @@
1
+ require 'neuron'
2
+ require 'active_support/hash_with_indifferent_access'
3
+
4
+ module Neuron
5
+ module Application
6
+ class Base
7
+ include Singleton
8
+
9
+ def initialize
10
+ @meta = {}
11
+ end
12
+
13
+ def meta
14
+ @meta[I18n.locale] ||= I18n.t('application.meta').with_indifferent_access
15
+ end
16
+
17
+ def title
18
+ meta[:title]
19
+ end
20
+
21
+ def keywords
22
+ meta[:keywords]
23
+ end
24
+
25
+ def description
26
+ meta[:description]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'neuron'
2
+ require 'active_support/concern'
3
+
4
+ module Neuron
5
+ module Controller
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def append_neuron_view_path_resolver
10
+ append_view_path Neuron::Resolver.new
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ require 'neuron'
3
+
4
+ module Neuron
5
+ # Navigational helpers: page and head titles
6
+ module Navigation
7
+ class Title
8
+ attr_accessor :default_options
9
+ attr_reader :view
10
+
11
+ class << self
12
+ def navigation_title(controller, action = :index, options = {})
13
+ I18n.t("navigation.#{controller}.#{action}", options)
14
+ end
15
+ end
16
+
17
+ def initialize(view, options = {})
18
+ @view = view
19
+ @navigation_title = nil
20
+ @page_title = nil
21
+ @head_title = nil
22
+ @default_options = {title_separator: ' — '}.merge(options)
23
+ end
24
+
25
+ def page_title(title = nil, options = {})
26
+ options = {default: navigation_title}.merge(default_options).merge(options)
27
+ @page_title ||= title || view.t('.title', options)
28
+ end
29
+
30
+ def navigation_title(title = nil, options = {})
31
+ options = {default: @page_title || view.view_name.humanize}.merge(default_options).merge(options)
32
+ @navigation_title ||= title || self.class.navigation_title(view.controller_i18n_scope, view.view_name, options)
33
+ end
34
+
35
+ def head_title(title = nil, options = {})
36
+ options = default_options.merge(options)
37
+ @head_title ||= title || view.strip_tags([navigation_title, application.title].compact.join(options[:title_separator]))
38
+ end
39
+
40
+ protected
41
+
42
+ def application
43
+ @application ||= Neuron::Application::Base.instance
44
+ end
45
+ end
46
+
47
+ module View
48
+ # Title of the current page
49
+ # @param [String, nil] title title to set
50
+ # @param [Hash] options options to {I18n#translate} if building default title
51
+ def page_title(title = nil, options = {})
52
+ neuron_title.page_title(title, options)
53
+ end
54
+
55
+ def navigation_title(title = nil, options = {})
56
+ neuron_title.navigation_title(title, options)
57
+ end
58
+
59
+ def head_title(title = nil, options = {})
60
+ neuron_title.head_title(title, options)
61
+ end
62
+
63
+ def title(new_title = nil, options = {})
64
+ tag = options.delete(:tag) { :h1 }
65
+ content_tag(tag, page_title(new_title, options))
66
+ end
67
+
68
+ protected
69
+
70
+ def neuron_title
71
+ @neuron_title ||= Neuron::Navigation::Title.new(self)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,14 @@
1
+ require 'neuron'
2
+ require 'action_view/template/resolver'
3
+
4
+ module Neuron
5
+ class Resolver < ::ActionView::FileSystemResolver
6
+ def initialize
7
+ super('app/views/neuron')
8
+ end
9
+
10
+ def find_templates(name, prefix, partial, details)
11
+ super(name, 'defaults', partial, details)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Neuron
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,63 @@
1
+ require 'neuron'
2
+
3
+ module Neuron
4
+ module View
5
+ def block_modifiers(block, *modifiers)
6
+ klasses = [block]
7
+ if (options = modifiers.extract_options!).any?
8
+ options.each do |modifier, needed|
9
+ klasses << "#{block}_#{modifier}" if needed
10
+ end
11
+ end
12
+ klasses += modifiers.collect { |modifier| "#{block}_#{modifier}" }
13
+ {:class => klasses.join(' ')}
14
+ end
15
+
16
+ # Make body’s modifiers, based on controller_name and action_name
17
+ def body_attributes
18
+ controller_class = controller_i18n_scope.gsub(/[._]/, '-')
19
+ block_modifiers("m-#{controller_class}", view_name).tap do |hash|
20
+ hash[:class] << " m-action_#{view_name}"
21
+ end
22
+ end
23
+
24
+ def html_attributes
25
+ {:lang => I18n.locale}
26
+ end
27
+
28
+ def human(klass, attribute = nil)
29
+ attribute ? klass.human_attribute_name(attribute) : klass.name.human
30
+ 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
36
+
37
+ # Build canonical url for given resource
38
+ def canonical_url(resource, options = {})
39
+ polymorphic_url(resource, options)
40
+ end
41
+
42
+ def view_name
43
+ {create: 'new', update: 'edit'}[action_name] || action_name
44
+ end
45
+
46
+ def controller_i18n_scope
47
+ @controller_i18n_scope ||= controller.controller_path.gsub(%r{/}, '.')
48
+ end
49
+
50
+ def time(time, options = {})
51
+ format = options.delete(:format) { :short }
52
+ title = options.delete(:title) do
53
+ title_format = options.delete(:title_format) { :long }
54
+ l(time, format: title_format)
55
+ end
56
+ content_tag(:time, l(time, format: format), options.merge(datetime: time.xmlschema, title: title))
57
+ end
58
+
59
+ def date(date, options = {})
60
+ time(date.to_date)
61
+ end
62
+ end
63
+ end
data/lib/neuron.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'neuron/version'
2
+
3
+ module Neuron
4
+ autoload :Application, 'neuron/application'
5
+ autoload :Controller, 'neuron/controller'
6
+ autoload :Navigation, 'neuron/navigation'
7
+ autoload :Resolver, 'neuron/resolver'
8
+ autoload :View, 'neuron/view'
9
+
10
+ def self.enable!
11
+ if defined?(ActionView)
12
+ ActionView::Base.send :include, Neuron::View
13
+ ActionView::Base.send :include, Neuron::Navigation::View
14
+ end
15
+ if defined?(ActionController)
16
+ ActionController::Base.send :include, Neuron::Controller
17
+ end
18
+ end
19
+ end
20
+
21
+ Neuron.enable! if defined?(Rails)
data/neuron.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'neuron/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'neuron'
7
+ s.version = Neuron::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Alexander Semyonov']
10
+ s.email = ['al@semyonov.us']
11
+ s.homepage = ''
12
+ s.summary = %q{Tools for decrease code duplication in rails applications}
13
+ s.description = %q{Code reused in many applications}
14
+
15
+ s.rubyforge_project = 'neuron'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neuron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Semyonov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-29 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Code reused in many applications
15
+ email:
16
+ - al@semyonov.us
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - lib/neuron.rb
25
+ - lib/neuron/application.rb
26
+ - lib/neuron/controller.rb
27
+ - lib/neuron/navigation.rb
28
+ - lib/neuron/resolver.rb
29
+ - lib/neuron/version.rb
30
+ - lib/neuron/view.rb
31
+ - neuron.gemspec
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: neuron
52
+ rubygems_version: 1.7.2
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Tools for decrease code duplication in rails applications
56
+ test_files: []
57
+ has_rdoc: