bsm-breadcrumbs 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,24 @@
1
1
  class Breadcrumbs
2
2
  module Render
3
3
  class Base # :nodoc: all
4
- attr_accessor :breadcrumbs
5
- attr_accessor :default_options
6
4
 
7
- def initialize(breadcrumbs, default_options = {})
5
+ attr_reader :breadcrumbs, :options
6
+
7
+ def initialize(breadcrumbs, options = {})
8
8
  @breadcrumbs = breadcrumbs
9
- @default_options = default_options
9
+ @options = default_options.merge(options)
10
+ end
11
+
12
+ # @abstract
13
+ # @return [Hash] default options
14
+ def default_options
15
+ { :class => "breadcrumbs" }
16
+ end
17
+
18
+ # @abstract
19
+ # @return [String] the rendered HTML
20
+ def render
21
+ ""
10
22
  end
11
23
 
12
24
  # Build a HTML tag.
@@ -0,0 +1,42 @@
1
+ class Breadcrumbs
2
+ module Render
3
+ class Bootstrap < List # :nodoc: all
4
+
5
+ attr_reader :separator
6
+
7
+ # @overload
8
+ def initialize(*)
9
+ super
10
+ @separator = options.delete(:separator)
11
+ end
12
+
13
+ # @overload
14
+ def default_options
15
+ super.merge(:class => "breadcrumb", :separator => "/")
16
+ end
17
+
18
+ # @overload
19
+ def render_item(item, i, size)
20
+ html_opts, suffix = {}, nil
21
+ if i == size - 1
22
+ html_opts.update :class => "active"
23
+ elsif separator
24
+ suffix = tag(:span, separator, :class => "divider")
25
+ end
26
+
27
+ text, url, options = *item
28
+ text = [escape(text), suffix].join
29
+ text = wrap_item(url, text, options)
30
+ tag(:li, text, html_opts)
31
+ end
32
+
33
+ protected
34
+
35
+ # @overload
36
+ def wrap_item(url, text, *)
37
+ url ? tag(:a, text, :href => url) : text
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,9 +1,14 @@
1
1
  class Breadcrumbs
2
2
  module Render
3
3
  class Inline < Base # :nodoc: all
4
- def render
5
- options = {:class => "breadcrumbs", :separator => "&#187;"}.merge(default_options)
6
4
 
5
+ # @overload
6
+ def default_options
7
+ super.merge(:separator => "&#187;")
8
+ end
9
+
10
+ # @overload
11
+ def render
7
12
  html = []
8
13
  size = breadcrumbs.size
9
14
 
@@ -1,11 +1,22 @@
1
1
  class Breadcrumbs
2
2
  module Render
3
3
  class List < Base # :nodoc: all
4
- def render
5
- options = {
6
- :class => "breadcrumbs"
7
- }.merge(default_options)
8
4
 
5
+ attr_reader :list_style
6
+
7
+ # @overload
8
+ def initialize(*)
9
+ super
10
+ @list_style = options.delete(:tag) || :ul
11
+ end
12
+
13
+ # @overload
14
+ def default_options
15
+ super.merge(:tag => :ul)
16
+ end
17
+
18
+ # @overload
19
+ def render
9
20
  tag(list_style, options) do
10
21
  html = ""
11
22
  size = breadcrumbs.size
@@ -18,10 +29,6 @@ class Breadcrumbs
18
29
  end
19
30
  end
20
31
 
21
- def list_style
22
- :ul
23
- end
24
-
25
32
  def render_item(item, i, size)
26
33
  css = []
27
34
  css << "first" if i == 0
@@ -2,5 +2,5 @@ module Breadcrumbs::Render
2
2
  autoload :Base, "breadcrumbs/render/base"
3
3
  autoload :Inline, "breadcrumbs/render/inline"
4
4
  autoload :List, "breadcrumbs/render/list"
5
- autoload :OrderedList, "breadcrumbs/render/ordered_list"
5
+ autoload :Bootstrap, "breadcrumbs/render/bootstrap"
6
6
  end
@@ -1,8 +1,8 @@
1
1
  class Breadcrumbs < Array
2
2
  module Version # :nodoc: all
3
3
  MAJOR = 0
4
- MINOR = 3
5
- PATCH = 3
4
+ MINOR = 4
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/lib/breadcrumbs.rb CHANGED
@@ -69,7 +69,9 @@ class Breadcrumbs < Array
69
69
  # breadcrumbs.render(:format => :inline)
70
70
  # breadcrumbs.render(:format => :inline, :separator => "|")
71
71
  # breadcrumbs.render(:format => :list)
72
- # breadcrumbs.render(:format => :ordered_list)
72
+ # breadcrumbs.render(:format => :list, :tag => :ol)
73
+ # breadcrumbs.render(:format => :bootstrap)
74
+ # breadcrumbs.render(:format => :bootstrap, :separator => "&raquo;")
73
75
  # breadcrumbs.render(:id => "breadcrumbs")
74
76
  # breadcrumbs.render(:class => "breadcrumbs")
75
77
  #
@@ -87,11 +89,9 @@ class Breadcrumbs < Array
87
89
  # breadcrumbs.render(:format => :dl)
88
90
  #
89
91
  def render(options = {})
90
- options[:format] ||= :list
91
-
92
- klass_name = options[:format].to_s.classify
93
- klass = Breadcrumbs::Render.const_get(klass_name)
94
- html = klass.new(self, options).render
92
+ format = options.delete(:format) || :list
93
+ klass = Breadcrumbs::Render.const_get(format.to_s.classify)
94
+ html = klass.new(self, options).render
95
95
 
96
96
  html.respond_to?(:html_safe) ? html.html_safe : html
97
97
  end
@@ -115,4 +115,4 @@ class Breadcrumbs < Array
115
115
 
116
116
  end
117
117
 
118
- require "breadcrumbs/action_controller_ext"
118
+ require "breadcrumbs/action_controller_ext"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsm-breadcrumbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-21 00:00:00.000000000Z
13
+ date: 2012-01-02 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
17
- requirement: &8433300 !ruby/object:Gem::Requirement
17
+ requirement: &18075840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 3.2.0
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *8433300
28
+ version_requirements: *18075840
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: activemodel
31
- requirement: &8430720 !ruby/object:Gem::Requirement
31
+ requirement: &18075080 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ! '>='
@@ -39,10 +39,10 @@ dependencies:
39
39
  version: 3.2.0
40
40
  type: :runtime
41
41
  prerelease: false
42
- version_requirements: *8430720
42
+ version_requirements: *18075080
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
- requirement: &8422620 !ruby/object:Gem::Requirement
45
+ requirement: &18074440 !ruby/object:Gem::Requirement
46
46
  none: false
47
47
  requirements:
48
48
  - - ! '>='
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: '0'
51
51
  type: :development
52
52
  prerelease: false
53
- version_requirements: *8422620
53
+ version_requirements: *18074440
54
54
  description:
55
55
  email: dimitrij@blacksquaremedia.com
56
56
  executables: []
@@ -58,14 +58,14 @@ extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
60
  - README.rdoc
61
- - lib/breadcrumbs.rb
62
- - lib/breadcrumbs/render.rb
63
- - lib/breadcrumbs/action_controller_ext.rb
64
- - lib/breadcrumbs/version.rb
65
- - lib/breadcrumbs/render/ordered_list.rb
66
- - lib/breadcrumbs/render/inline.rb
61
+ - lib/breadcrumbs/render/bootstrap.rb
67
62
  - lib/breadcrumbs/render/base.rb
68
63
  - lib/breadcrumbs/render/list.rb
64
+ - lib/breadcrumbs/render/inline.rb
65
+ - lib/breadcrumbs/action_controller_ext.rb
66
+ - lib/breadcrumbs/render.rb
67
+ - lib/breadcrumbs/version.rb
68
+ - lib/breadcrumbs.rb
69
69
  homepage: https://github.com/bsm/breadcrumbs
70
70
  licenses: []
71
71
  post_install_message:
@@ -1,9 +0,0 @@
1
- class Breadcrumbs
2
- module Render
3
- class OrderedList < List # :nodoc: all
4
- def list_style
5
- :ol
6
- end
7
- end
8
- end
9
- end