loaf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,56 @@
1
+ = loaf
2
+
3
+ Breadcrumbs creation library.
4
+
5
+ * Helps in creating breadcrumbs.
6
+ * Uses controllers to specify names and routes for parts of breadcrum trails or collections of breadcrumbs.
7
+ * Stays out of your way when it comes to markup exposing only single helper method to access breadcrumb data.
8
+
9
+ == Installation
10
+
11
+ Install from source:
12
+
13
+ gem install loaf
14
+
15
+ Add to your Gemfile:
16
+
17
+ gem 'loaf'
18
+
19
+ == Configuration
20
+
21
+ There is small set of custom opinionated defaults. However, to override them in your views just pass an option hash.
22
+
23
+ == Usage
24
+
25
+ In controller:
26
+
27
+ You can add breadcrumbs for nested resources, for instance, article categories:
28
+
29
+ You can add semantic markup in your view to show breadcrumbs
30
+
31
+ <ul id="breadcrumbs">
32
+ <%- breadcrumbs :crumb_length => 5 do |name, url, styles| -%>
33
+ <li class="<%= styles %>"><%= link_to name, url %></li>
34
+ <%- end -%>
35
+ </ul>
36
+
37
+ == TODO
38
+
39
+ * Add ability to add breadcrumbs for nested resources
40
+ * Add support for name internationalisation
41
+ * Finish specs
42
+
43
+ == Contributing to loaf
44
+
45
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
46
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
47
+ * Fork the project
48
+ * Start a feature/bugfix branch
49
+ * Commit and push until you are happy with your contribution
50
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
51
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
52
+
53
+ == Copyright
54
+
55
+ Copyright (c) 2011 Piotr Murach. See LICENSE.txt for
56
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/loaf/version.rb'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "loaf"
19
+ gem.homepage = "http://github.com/peter-murach/loaf"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{TODO: one-line summary of your gem}
22
+ gem.description = %Q{TODO: longer description of your gem}
23
+ gem.email = "pmurach@gmail.com"
24
+ gem.authors = ["Piotr Murach"]
25
+ gem.version = Loaf::Version::STRING
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "loaf #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
@@ -0,0 +1,38 @@
1
+ module Loaf
2
+ class Builder
3
+
4
+ attr_accessor :crumbs
5
+
6
+ def initialize(view_context, collection, options = {})
7
+
8
+ @params = default_options.merge(options)
9
+
10
+ set_breadcrumbs
11
+
12
+ build @params
13
+ end
14
+
15
+ private
16
+
17
+ def set_breadcrumbs(breadcrumbs)
18
+ @params[:breadcrumbs] = breadcrumbs
19
+ end
20
+
21
+ def build
22
+ @params.each_pair do |option, value|
23
+
24
+ end
25
+ end
26
+
27
+ def default_options
28
+ {
29
+ :breadcrumbs => [],
30
+ :delimiter => " &raquo ",
31
+ :style_class => 'selected',
32
+ :crumb_length => '30',
33
+ :last_crumb_linked => false
34
+ }
35
+ end
36
+
37
+ end # Builder
38
+ end # Loaf
@@ -0,0 +1,43 @@
1
+ module Loaf
2
+ module Configuration
3
+
4
+ VALID_ATTRIBUTES = [
5
+ :locales_path,
6
+ :style_classes,
7
+ :crumb_length,
8
+ :last_crumb_linked,
9
+ :capitalize
10
+ ]
11
+
12
+ attr_accessor *VALID_ATTRIBUTES
13
+
14
+ DEFAULT_LOCALES_PATH = "/"
15
+
16
+ DEFAULT_STYLE_CLASSES = 'selected'
17
+
18
+ DEFAULT_CRUMB_LENGTH = 30
19
+
20
+ DEFAULT_LAST_CRUMB_LINKED = false
21
+
22
+ DEFAULT_CAPITALIZE = false
23
+
24
+ def configure
25
+ yield self
26
+ end
27
+
28
+ def self.extended(base)
29
+ base.setup(self)
30
+ end
31
+
32
+ def config
33
+ VALID_ATTRIBUTES.inject({}) { |hash, k| hash[k] = send(k); hash }
34
+ end
35
+
36
+ def setup(parent)
37
+ VALID_ATTRIBUTES.each do |attr|
38
+ send("#{attr}=", parent.const_get("DEFAULT_#{attr.to_s.upcase}"))
39
+ end
40
+ end
41
+
42
+ end # Configuration
43
+ end # Loaf
@@ -0,0 +1,68 @@
1
+ module Loaf
2
+ module Filters
3
+
4
+ Crumb = Struct.new(:name, :url, :styles)
5
+
6
+ module ClassMethods
7
+
8
+ def add_breadcrumb(name, url, options = {})
9
+ before_filter(options) do |instance|
10
+ instance.send(:add_breadcrumb, _normalize_name(name), url)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def _normalize_name(name=nil)
17
+ case name
18
+ when NilClass
19
+ when Proc
20
+ name.call
21
+ when Symbol
22
+ name.to_s
23
+ else
24
+ name
25
+ end
26
+ end
27
+
28
+ def _process_url(url)
29
+
30
+ end
31
+ end
32
+
33
+ module InstanceMethods
34
+
35
+ # Add collection of nested breadcrumbs.
36
+ def add_breadcrumbs(collection=[], options={})
37
+ return nil unless collection.is_a? Array
38
+
39
+ attr = options[:attr].delete
40
+ prefix = options[:prefix].delete
41
+
42
+ collection.each do |item|
43
+ add_breadcrumb("#{item.send(attr.to_sym)}", prefix + '(' + item + ')' )
44
+ end
45
+ end
46
+
47
+ def add_breadcrumb(name, url)
48
+ _breadcrumbs << Crumb.new(name, url)
49
+ end
50
+
51
+ def _breadcrumbs
52
+ @_breadcrumbs ||= []
53
+ end
54
+
55
+ def clear_crumbs
56
+ _breadcrumbs.clear
57
+ end
58
+
59
+ end # InstanceMethods
60
+
61
+ def self.included(base)
62
+ base.extend ClassMethods
63
+ base.send :include, InstanceMethods
64
+ base.send :helper_method, :_breadcrumbs
65
+ end
66
+
67
+ end # Filters
68
+ end # Loaf
@@ -0,0 +1,32 @@
1
+ require 'loaf/configuration'
2
+
3
+ module Loaf
4
+ module Helpers
5
+
6
+ class_eval do
7
+ define_method :config do |options|
8
+ Loaf.config
9
+ end
10
+ end
11
+
12
+ # Adds breadcrumbs in a view
13
+ def add_breadcrumb(name, url=nil)
14
+ _breadcrumbs.push(name, url)
15
+ end
16
+
17
+ def breadcrumbs(options={}, &block)
18
+ #builder = Loaf::Builder.new(options)
19
+ options = config.merge(options)
20
+
21
+ _breadcrumbs.each do |crumb|
22
+
23
+ name = crumb.name ? truncate(crumb.name.upcase, :length => options[:crumb_length]) : ''
24
+ url = eval(crumb.url)
25
+ styles = ( request.request_uri.split('?')[0] == url ? "#{options[:style_classes]}" : '' )
26
+
27
+ block.call(name, url, styles)
28
+ end
29
+ end
30
+
31
+ end # Helpers
32
+ end # Loaf
@@ -0,0 +1,20 @@
1
+ module Loaf
2
+
3
+ if defined? Rails::Railtie
4
+ class Railtie < Rails::Railtie
5
+ initializer "loaf.extend_action_controller_base" do |app|
6
+ ActiveSupport.on_load(:action_controller) do
7
+ Loaf::Railtie.insert
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ class Railtie
14
+ def self.insert
15
+ ActionController::Base.send :include, Loaf::Filters
16
+ ActionController::Base.helper Loaf::Helpers
17
+ end
18
+ end # Railtie
19
+
20
+ end # Loaf
@@ -0,0 +1,15 @@
1
+ module Loaf
2
+ module Translation
3
+
4
+ def set_title!
5
+ namespace = controller.controller_path.gsub("/", ".")
6
+ action = controller.action_name
7
+
8
+ i18n_options = {
9
+
10
+ }
11
+
12
+ I18n.t(title, i18n_options)
13
+ end
14
+ end
15
+ end # Loaf
@@ -0,0 +1,10 @@
1
+ module Loaf
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ BUILD = nil
7
+
8
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
9
+ end
10
+ end
data/lib/loaf.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'action_controller'
2
+ require 'loaf/configuration'
3
+
4
+ module Loaf
5
+ if defined? Rails::Railtie
6
+ require 'loaf/railtie'
7
+ else
8
+ autoload :Filters, 'loaf/filters'
9
+ autoload :Helpers, 'loaf/helpers'
10
+
11
+ ::ActionController::Base.send :include, Loaf::Filters
12
+ ::ActionController::Base.helper Loaf::Helpers
13
+ end
14
+
15
+ extend Configuration
16
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loaf
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Piotr Murach
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-10-23 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 1
30
+ - 0
31
+ version: 3.1.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 4
44
+ - 0
45
+ version: 2.4.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec-rails
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 0
58
+ - 0
59
+ version: 2.0.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: capybara
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 4
72
+ - 0
73
+ version: 0.4.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: bundler
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 0
86
+ - 0
87
+ version: 1.0.0
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: jeweler
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 1
99
+ - 6
100
+ - 4
101
+ version: 1.6.4
102
+ type: :development
103
+ version_requirements: *id006
104
+ description: Loaf helps you manage breadcrumbs in your rails app. It aims to handle crumb data through easy dsl and expose it through view helpers without any assumptions about markup.
105
+ email: ""
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files: []
111
+
112
+ files:
113
+ - lib/loaf/builder.rb
114
+ - lib/loaf/configuration.rb
115
+ - lib/loaf/filters.rb
116
+ - lib/loaf/helpers.rb
117
+ - lib/loaf/railtie.rb
118
+ - lib/loaf/translation.rb
119
+ - lib/loaf/version.rb
120
+ - lib/loaf.rb
121
+ - Rakefile
122
+ - Gemfile
123
+ - README.rdoc
124
+ has_rdoc: true
125
+ homepage: https://github.com/peter-murach/loaf
126
+ licenses: []
127
+
128
+ post_install_message:
129
+ rdoc_options: []
130
+
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.6
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Loaf is a breadcrumb managing gem.
154
+ test_files: []
155
+