Skip to content
Gretel extension for supporting JSON-LD breadcrumbs
Ruby HTML
Branch: master
Clone or download
yasaichi Merge pull request #11 from yasaichi/ci-against-latest-rubys
CI against the latest Ruby (adding Ruby 2.5 and 2.6)
Latest commit fd00d2e Apr 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
gemfiles
lib/gretel Bump version to 0.2.0 Nov 25, 2017
spec Use JSONLD as module name instead of Jsonld Nov 25, 2017
.codeclimate.yml
.gitignore
.reek Introduce Reek Nov 21, 2017
.rspec Introduce RSpec with `rails generate rspec:install` Nov 21, 2017
.rubocop.yml
.travis.yml CI against the latest Rubys (adding Ruby 2.5 and 2.6) Apr 28, 2019
Appraisals
CHANGELOG.md
Gemfile Introduce pry for better dubbuging Nov 23, 2017
MIT-LICENSE
README.md Tiny fix of README Apr 28, 2019
Rakefile Use JSONLD as module name instead of Jsonld Nov 25, 2017
gretel-jsonld.gemspec
sideci.yml

README.md

gretel-jsonld

Gem Version Build Status Code Climate Test Coverage

gretel-jsonld enables gretel gem to handle JSON-LD based breadcrumbs.

Installation

Add this line to your application's Gemfile:

gem 'gretel-jsonld'

And then execute:

$ bundle

Usage

First, run the installation generator with:

$ rails generate gretel:install

Next, define "crumbs" in config/breadcrumbs.rb:

# See also: https://github.com/lassebunk/gretel#more-examples

# Root crumb
crumb :root do
  link 'Home', root_path
end

# Issue list
crumb :issues do
  link 'All issues', issues_path
end

# Issue
crumb :issue do |issue|
  link issue.title, issue
  parent :issues
end

Then, add this line to your application's layout:

<%= jsonld_breadcrumbs %>

Finally, specify a current breadcrumb in each view:

<% breadcrumb :issue, @issue %>

This will generate the following breadcrumbs, marked up with JSON-LD (indented for readability):

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "item": {
          "@id": "/",
          "name": "Home"
        }
      },
      {
        "@type": "ListItem",
        "position": 2,
        "item": {
          "@id": "/issues",
          "name": "All issues"
        }
      },
      {
        "@type": "ListItem",
        "position": 3,
        "item": {
          "@id": "/issues/46",
          "name": "My Issue"
        }
      }
    ]
  }
</script>

Options

You can pass jsonld_breadcrumbs the same options as breadcrumbs:

<%= jsonld_breadcrumbs link_current_to_request_path: false %>

For further information, please see gretel's documentation.

Supported versions

Note that gretel-jsonld doesn't support all versions of gretel, Ruby and Rails:

  • gretel: gretel-jsonld supports only 3.x for now
  • Ruby: gretel 3.x supports 1.9.3 or later, but gretel-jsonld does only 2.2.2 or later
  • Rails: gretel 3.x supports 3.1 or later, but gretel-jsonld does only 3.2 or later

Contributing

You should follow the steps below:

  1. Fork the repository
  2. Create a feature branch: git checkout -b add-new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push the branch: git push origin add-new-feature
  5. Send us a pull request

License

The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.