loaf 0.1.0 → 0.1.1
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/README.rdoc +25 -10
- data/lib/loaf/configuration.rb +6 -3
- data/lib/loaf/filters.rb +20 -9
- data/lib/loaf/helpers.rb +23 -6
- data/lib/loaf/version.rb +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,36 +1,51 @@
|
|
1
|
-
=
|
1
|
+
= Loaf
|
2
2
|
|
3
3
|
Breadcrumbs creation library.
|
4
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.
|
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
8
|
|
9
9
|
== Installation
|
10
10
|
|
11
11
|
Install from source:
|
12
|
-
|
12
|
+
|
13
13
|
gem install loaf
|
14
14
|
|
15
15
|
Add to your Gemfile:
|
16
|
-
|
16
|
+
|
17
17
|
gem 'loaf'
|
18
18
|
|
19
19
|
== Configuration
|
20
20
|
|
21
|
-
There is small set of custom opinionated defaults. However, to override them in your views just pass an option hash.
|
21
|
+
There is small set of custom opinionated defaults. However, to override them in your views just pass an option hash. The following options are valid:
|
22
|
+
|
23
|
+
:crumb_length # integer, default length is 30 characters
|
24
|
+
:root # boolean, default is true, displays the home crumb
|
22
25
|
|
23
26
|
== Usage
|
24
27
|
|
25
28
|
In controller:
|
26
29
|
|
30
|
+
class Blog::CategoriesController < ApplicationController
|
31
|
+
|
32
|
+
add_breadcrumb 'Article Categories', 'blog_categories_path', :only => [:show]
|
33
|
+
|
34
|
+
def show
|
35
|
+
add_breadcrumb "#{@category.title}", 'blog_category_path(@category)'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
27
39
|
You can add breadcrumbs for nested resources, for instance, article categories:
|
28
40
|
|
29
41
|
You can add semantic markup in your view to show breadcrumbs
|
30
42
|
|
31
43
|
<ul id="breadcrumbs">
|
32
|
-
<%- breadcrumbs :crumb_length =>
|
33
|
-
<li class="<%= styles %>"
|
44
|
+
<%- breadcrumbs :crumb_length => 20 do |name, url, styles| -%>
|
45
|
+
<li class="<%= styles %>">
|
46
|
+
<%= link_to name, url %>
|
47
|
+
<span><%= styles == 'selected' ? '' : '::' %></span>
|
48
|
+
</li>
|
34
49
|
<%- end -%>
|
35
50
|
</ul>
|
36
51
|
|
@@ -41,7 +56,7 @@ You can add semantic markup in your view to show breadcrumbs
|
|
41
56
|
* Finish specs
|
42
57
|
|
43
58
|
== Contributing to loaf
|
44
|
-
|
59
|
+
|
45
60
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
46
61
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
47
62
|
* Fork the project
|
data/lib/loaf/configuration.rb
CHANGED
@@ -6,13 +6,14 @@ module Loaf
|
|
6
6
|
:style_classes,
|
7
7
|
:crumb_length,
|
8
8
|
:last_crumb_linked,
|
9
|
-
:capitalize
|
9
|
+
:capitalize,
|
10
|
+
:root
|
10
11
|
]
|
11
12
|
|
12
13
|
attr_accessor *VALID_ATTRIBUTES
|
13
14
|
|
14
15
|
DEFAULT_LOCALES_PATH = "/"
|
15
|
-
|
16
|
+
|
16
17
|
DEFAULT_STYLE_CLASSES = 'selected'
|
17
18
|
|
18
19
|
DEFAULT_CRUMB_LENGTH = 30
|
@@ -21,6 +22,8 @@ module Loaf
|
|
21
22
|
|
22
23
|
DEFAULT_CAPITALIZE = false
|
23
24
|
|
25
|
+
DEFAULT_ROOT = true
|
26
|
+
|
24
27
|
def configure
|
25
28
|
yield self
|
26
29
|
end
|
@@ -38,6 +41,6 @@ module Loaf
|
|
38
41
|
send("#{attr}=", parent.const_get("DEFAULT_#{attr.to_s.upcase}"))
|
39
42
|
end
|
40
43
|
end
|
41
|
-
|
44
|
+
|
42
45
|
end # Configuration
|
43
46
|
end # Loaf
|
data/lib/loaf/filters.rb
CHANGED
@@ -26,21 +26,26 @@ module Loaf
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def _process_url(url)
|
29
|
-
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
module InstanceMethods
|
34
33
|
|
35
34
|
# Add collection of nested breadcrumbs.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
# * <tt>collection</tt> - required collection of object for iteration
|
36
|
+
# * <tt>field</tt> - required object attribute name
|
37
|
+
#
|
38
|
+
def add_breadcrumbs(collection, field, options={})
|
39
|
+
namespace = nil
|
40
|
+
item_set = if _check_if_nested collection
|
41
|
+
items = collection.pop
|
42
|
+
namespace = collection
|
43
|
+
items
|
44
|
+
else
|
45
|
+
collection
|
46
|
+
end
|
47
|
+
item_set.each do |item|
|
48
|
+
add_breadcrumb item.send(field.to_sym), [ namespace, item ].flatten.compact
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -56,6 +61,12 @@ module Loaf
|
|
56
61
|
_breadcrumbs.clear
|
57
62
|
end
|
58
63
|
|
64
|
+
private
|
65
|
+
|
66
|
+
def _check_if_nested(collection)
|
67
|
+
collection.last.is_a? Array
|
68
|
+
end
|
69
|
+
|
59
70
|
end # InstanceMethods
|
60
71
|
|
61
72
|
def self.included(base)
|
data/lib/loaf/helpers.rb
CHANGED
@@ -2,7 +2,7 @@ require 'loaf/configuration'
|
|
2
2
|
|
3
3
|
module Loaf
|
4
4
|
module Helpers
|
5
|
-
|
5
|
+
|
6
6
|
class_eval do
|
7
7
|
define_method :config do |options|
|
8
8
|
Loaf.config
|
@@ -13,20 +13,37 @@ module Loaf
|
|
13
13
|
def add_breadcrumb(name, url=nil)
|
14
14
|
_breadcrumbs.push(name, url)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def breadcrumbs(options={}, &block)
|
18
18
|
#builder = Loaf::Builder.new(options)
|
19
19
|
options = config.merge(options)
|
20
20
|
|
21
21
|
_breadcrumbs.each do |crumb|
|
22
|
-
|
23
|
-
name =
|
24
|
-
|
22
|
+
|
23
|
+
name = if crumb.name
|
24
|
+
formatted = options[:capitalize] ? crumb.name.capitalize : crumb.name
|
25
|
+
truncate(formatted, :length => options[:crumb_length])
|
26
|
+
else
|
27
|
+
'[name-error]'
|
28
|
+
end
|
29
|
+
|
30
|
+
url = url_for _process_url_for(crumb.url)
|
31
|
+
|
25
32
|
styles = ( request.request_uri.split('?')[0] == url ? "#{options[:style_classes]}" : '' )
|
26
|
-
|
33
|
+
|
27
34
|
block.call(name, url, styles)
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def _process_url_for(url)
|
41
|
+
if url.is_a?(String) || url.is_a?(Symbol)
|
42
|
+
return send url
|
43
|
+
else
|
44
|
+
return url
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
31
48
|
end # Helpers
|
32
49
|
end # Loaf
|
data/lib/loaf/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Piotr Murach
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-11-20 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|