-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from muryoimpl/develop
Bump 0.1.0
- Loading branch information
Showing
33 changed files
with
635 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: ruby | ||
sudo: false | ||
rvm: | ||
- 2.1.8 | ||
- 2.2.4 | ||
- 2.3.0 | ||
|
||
gemfile: | ||
- gemfiles/Gemfile-4.1.x | ||
- gemfiles/Gemfile-4.2.x | ||
- gemfiles/Gemfile-5.0.x | ||
|
||
before_script: | ||
- 'bundle install' | ||
- 'cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../..' | ||
|
||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Buoys | ||
|
||
Buoys is a Ruby on Rails breadcrumb plugin like [gretel](https://github.com/lassebunk/gretel). | ||
|
||
## Motivation | ||
|
||
I like [gretel](https://github.com/lassebunk/gretel) and respect its idea, but I want to create simpler breadcrumb library like [gretel](https://github.com/lassebunk/gretel) using I18n. | ||
|
||
## Installation | ||
|
||
In your Gemfile | ||
|
||
```ruby | ||
gem 'buoys' | ||
``` | ||
|
||
And run: | ||
|
||
```ruby | ||
$ bundle install | ||
``` | ||
|
||
## Example | ||
|
||
Start by generating configuration and example files. | ||
```ruby | ||
$ bin/rails g buoys:install | ||
create config/locale/buoys.en.yml | ||
create app/views/breadcrumbs/_buoys.html.erb | ||
create config/buoys/breadcrumbs.rb | ||
``` | ||
|
||
Then, in `config/buoys/breadcrumbs.rb` | ||
```ruby | ||
buoy :stories do | ||
link 'Stories', stories_path | ||
end | ||
|
||
# 'crumb' is the alias of 'buoy' | ||
# ex) | ||
crumb :stories do | ||
link 'Stories', stories_path | ||
end | ||
|
||
# link's first argument, it is used as I18n key and defalt value. | ||
# The key is searched in the scope of 'buoys.breadcrumbs'. | ||
# ex) | ||
buoy :story do |story| | ||
link :story, story_path(story) | ||
# same as `link I18n.t('story', scope: 'buoys.breadcrumbs', default: 'story'), story_path(story)` | ||
end | ||
|
||
# You can alse override Buoys configuration | ||
# ex) | ||
buoy :story_tasks do |story| | ||
link :story_tasks, story_tasks_path | ||
pre_buoy :story, story, {link_current: true} | ||
end | ||
|
||
# You can use 'pre_buoy' as parent. 'parent' is the alias of re_buoy` | ||
# ex) | ||
buoy :story_tasks do |story| | ||
link :story_tasks, story_tasks_path | ||
parent :story, story | ||
end | ||
``` | ||
|
||
Then, set the current buoy(breadcrumb) at the top of view file (like `app/views/stories/index.html.erb`). | ||
|
||
```ruby | ||
<% buoy :stories %> | ||
``` | ||
Then, in `app/views/layouts/application.html.erb`. | ||
```ruby | ||
<%= render partial: 'breadcrumbs/buoys' %> | ||
``` | ||
|
||
Then, You can build and change breadcrumb `app/views/breadcrumbs/_buoys.html.erb` | ||
|
||
```erb | ||
<% if buoys.any? %> | ||
<ul> | ||
<% buoys.each do |link| %> | ||
<li> | ||
<%# if 'link.current?' is true, link.options includes {class: 'current'}. %> | ||
<%= link_to link.url, link.options do %> | ||
<span><%= link.text %></span> | ||
<% end %> | ||
<% if !link.current? %> | ||
<span> ></span> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
``` | ||
|
||
## Options | ||
|
||
| option | description | default | | ||
| -------------- | ----------- | ------- | | ||
| :link_current | whether current buoy(breadcrumb) should be linked to | false | | ||
| :current_class | CSS class for current link. if you set `nil`, it is not set CSS class | 'active' | | ||
|
||
Copyright (c) 2016 muryoimpl Released under the MIT license |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
# Maintain your gem's version: | ||
require "buoy/version" | ||
require "buoys/version" | ||
|
||
# Describe your gem and declare its dependencies: | ||
Gem::Specification.new do |s| | ||
s.name = "buoy" | ||
s.version = Buoy::VERSION | ||
s.name = "buoys" | ||
s.version = Buoys::VERSION | ||
s.authors = ["muryoimpl"] | ||
s.email = ["muryoimpl@gmail.com"] | ||
s.homepage = "TODO" | ||
s.summary = "TODO: Summary of Buoy." | ||
s.description = "TODO: Description of Buoy." | ||
s.homepage = "https://github.com/muryoimpl/buoys" | ||
s.summary = "A Ruby on Rails breadcrumbs plugin." | ||
s.description = "A Ruby on Rails breadcrumbs plugin." | ||
s.license = "MIT" | ||
|
||
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] | ||
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] | ||
s.test_files = Dir["test/**/*"] | ||
|
||
s.add_dependency "rails", "~> 4.2.5.1" | ||
s.add_dependency "rails", ">= 4.1.0" | ||
|
||
s.add_development_dependency "sqlite3" | ||
s.add_development_dependency "pry-rails" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rails', '~> 4.1.0' | ||
gem 'sqlite3' | ||
|
||
gem 'buoys', path: '../' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rails', '~> 4.2.0' | ||
gem 'sqlite3' | ||
|
||
gem 'buoys', path: '../' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rails', '~> 5.0.0.beta3' | ||
gem 'sqlite3' | ||
|
||
gem 'buoys', path: '../' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'buoys/version' | ||
require 'buoys/config' | ||
require 'buoys/loader' | ||
require 'buoys/link' | ||
require 'buoys/buoy' | ||
require 'buoys/renderer' | ||
require 'buoys/helper' | ||
|
||
module Buoys | ||
class << self | ||
def buoy_file_paths | ||
@buoy_file_paths ||= [ | ||
Rails.root.join('config', 'buoys', '**', '*.rb') | ||
] | ||
end | ||
|
||
def configure | ||
yield Buoys::Config | ||
end | ||
end | ||
end | ||
ActionView::Base.send :include, Buoys::Helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Buoys | ||
class Buoy | ||
attr_reader :previous, :context | ||
# buoy :account do | ||
# link 'Account', account_path | ||
# end | ||
# | ||
# buoy :account_edit do |account| | ||
# link 'Account Show', show_account_path(account) | ||
# link 'Account Edit', edit_account_path(account) | ||
# pre_buoy :account | ||
# end | ||
def initialize(context, key, *args) | ||
block = Buoys::Loader.buoys[key] | ||
raise ArgumentError, "Buoys :#{key} is not found" unless block | ||
|
||
@key, @context = key, context | ||
instance_exec *args, &block | ||
end | ||
|
||
def link(key, *args) | ||
options = args.extract_options! | ||
path = args.shift | ||
url = path ? context.url_for(path) : path | ||
|
||
text = I18n.t(key, scope: 'buoys.breadcrumbs', default: key) | ||
|
||
links << Buoys::Link.new(text, url, options) | ||
end | ||
|
||
def links | ||
@links ||= [] | ||
end | ||
|
||
def pre_buoy(key, *args) | ||
@previous = Buoys::Buoy.new(context, key, args) | ||
end | ||
alias_method :parent, :pre_buoy | ||
|
||
def method_missing(method, *args, &block) | ||
context.send(method, *args, &block) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Buoys | ||
class Config | ||
class << self | ||
attr_accessor :current_class | ||
|
||
attr_accessor :link_current | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Buoys | ||
module Helper | ||
# Declare the breadcrumb which want to render in view. | ||
# | ||
# <%= buoy :help, true %> | ||
def buoy(key, *args) | ||
@_buoys_renderer = Buoys::Renderer.new(self, key, *args) | ||
end | ||
alias_method :breadcrumb, :buoy | ||
|
||
# <% buoys.tap do |links| %> | ||
# <% if links.any? %> | ||
# <ul> | ||
# <% links.each do |link| %> | ||
# <li class="<%= link.class %>"> | ||
# <%= link_to link.text, link.url %> | ||
# </li> | ||
# <% end %> | ||
# </ul> | ||
# <% end %> | ||
# <% end %> | ||
def buoys | ||
buoys_renderer.render | ||
end | ||
alias_method :breadcrumbs, :buoys | ||
|
||
def buoys_renderer | ||
@_buoys_renderer ||= Buoys::Renderer.new(self, nil) | ||
end | ||
end | ||
end |
Oops, something went wrong.