diff --git a/README.md b/README.md
index 5d48544..70d3126 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,7 @@ Option | Description
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
:id | ID for the breadcrumbs container. | None
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
+:fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | None
:current_class | CSS class for the current link or span. Can be set to `nil` for no class. | `"current"`
:pretext_class | CSS class for the pretext, if given. Can be set to `nil` for no class. | `"pretext"`
:posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
@@ -107,6 +108,7 @@ Style | Description
`:ol` | Renders the links in `
` elements contained in an outer ``.
`:ul` | Renders the links in `- ` elements contained in an outer `
`.
`:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
+`:bootstrap4` | Renders the links for use in [Bootstrap v4](http://v4-alpha.getbootstrap.com/).
`:foundation5` | Renders the links for use in [Foundation 5](http://foundation.zurb.com/).
Or you can build the breadcrumbs manually for full customization; see below.
diff --git a/gemfiles/Gemfile-rails.4.0.x b/gemfiles/Gemfile-rails.4.0.x
index 6e4bc06..ad2d416 100644
--- a/gemfiles/Gemfile-rails.4.0.x
+++ b/gemfiles/Gemfile-rails.4.0.x
@@ -8,6 +8,12 @@ gem "sqlite3"
# jquery-rails is used by the dummy application
gem "jquery-rails"
+if RUBY_VERSION > '1.9.3'
+ gem 'mime-types'
+else
+ gem 'mime-types', '2.99'
+end
+
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
diff --git a/gemfiles/Gemfile-rails.4.1.x b/gemfiles/Gemfile-rails.4.1.x
index 0c78c88..e0fc3c9 100644
--- a/gemfiles/Gemfile-rails.4.1.x
+++ b/gemfiles/Gemfile-rails.4.1.x
@@ -8,6 +8,12 @@ gem "sqlite3"
# jquery-rails is used by the dummy application
gem "jquery-rails"
+if RUBY_VERSION > '1.9.3'
+ gem 'mime-types'
+else
+ gem 'mime-types', '2.99'
+end
+
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
diff --git a/lib/gretel/renderer.rb b/lib/gretel/renderer.rb
index cbe3468..52689dc 100644
--- a/lib/gretel/renderer.rb
+++ b/lib/gretel/renderer.rb
@@ -22,6 +22,7 @@ class Renderer
ol: { container_tag: :ol, fragment_tag: :li },
ul: { container_tag: :ul, fragment_tag: :li },
bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
+ bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
}
@@ -171,12 +172,12 @@ def render
# Loop through all but the last (current) link and build HTML of the fragments
fragments = links[0..-2].map do |link|
- render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
+ render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic], fragment_class: options[:fragment_class])
end
# The current link is handled a little differently, and is only linked if specified in the options
current_link = links.last
- fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], class: options[:current_class], current_link: current_link.url)
+ fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], fragment_class: options[:fragment_class], class: options[:current_class], current_link: current_link.url)
# Build the final HTML
html_fragments = []
@@ -208,6 +209,9 @@ def render_fragment(fragment_tag, text, url, semantic, options = {})
# Renders semantic fragment HTML.
def render_semantic_fragment(fragment_tag, text, url, options = {})
+ fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
+ fragment_class = nil if fragment_class.blank?
+
if fragment_tag
text = content_tag(:span, text, itemprop: "title")
@@ -218,23 +222,26 @@ def render_semantic_fragment(fragment_tag, text, url, options = {})
text = text + tag(:meta, itemprop: "url", content: current_url)
end
- content_tag(fragment_tag, text, class: options[:class], itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
+ content_tag(fragment_tag, text, class: fragment_class, itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
elsif url.present?
- content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: options[:class], itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
+ content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: fragment_class, itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
else
- content_tag(:span, content_tag(:span, text, class: options[:class], itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
+ content_tag(:span, content_tag(:span, text, class: fragment_class, itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
end
end
# Renders regular, non-semantic fragment HTML.
def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
+ fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
+ fragment_class = nil if fragment_class.blank?
+
if fragment_tag
text = breadcrumb_link_to(text, url) if url.present?
- content_tag(fragment_tag, text, class: options[:class])
+ content_tag(fragment_tag, text, class: fragment_class)
elsif url.present?
- breadcrumb_link_to(text, url, class: options[:class])
+ breadcrumb_link_to(text, url, class: fragment_class)
elsif options[:class].present?
- content_tag(:span, text, class: options[:class])
+ content_tag(:span, text, class: fragment_class)
else
text
end
diff --git a/test/helper_methods_test.rb b/test/helper_methods_test.rb
index 4a5ddb3..806fd0e 100644
--- a/test/helper_methods_test.rb
+++ b/test/helper_methods_test.rb
@@ -129,6 +129,12 @@ def itemscope_value
breadcrumbs(class: "custom_class").to_s
end
+ test "custom fragment class" do
+ breadcrumb :basic
+ assert_dom_equal %{},
+ breadcrumbs(fragment_class: "custom_fragment_class").to_s
+ end
+
test "custom current class" do
breadcrumb :basic
assert_dom_equal %{},
@@ -358,6 +364,12 @@ def itemscope_value
breadcrumbs(style: :bootstrap).to_s
end
+ test "bootstrap4 style" do
+ breadcrumb :basic
+ assert_dom_equal %{- Home
- About
},
+ breadcrumbs(style: :bootstrap4).to_s
+ end
+
test "foundation5 style" do
breadcrumb :basic
assert_dom_equal %{},