Skip to content

Commit

Permalink
Merge pull request #2 from muryoimpl/develop
Browse files Browse the repository at this point in the history
Bump 0.1.0
  • Loading branch information
muryoimpl committed Mar 10, 2016
2 parents 86d3490 + c4aeaf2 commit 0c037fa
Show file tree
Hide file tree
Showing 33 changed files with 635 additions and 84 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
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
20 changes: 15 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
buoy (0.0.1)
rails (~> 4.2.5.1)
buoys (0.1.0)
rails (>= 4.1.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -44,7 +44,8 @@ GEM
tzinfo (~> 1.1)
arel (6.0.3)
builder (3.2.2)
concurrent-ruby (1.0.0)
coderay (1.1.1)
concurrent-ruby (1.0.1)
erubis (2.7.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
Expand All @@ -54,11 +55,18 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99.1)
mini_portile2 (2.0.0)
minitest (5.8.4)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -87,10 +95,11 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
slop (3.6.0)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.2)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand All @@ -104,7 +113,8 @@ PLATFORMS
ruby

DEPENDENCIES
buoy!
buoys!
pry-rails
sqlite3

BUNDLED WITH
Expand Down
106 changes: 106 additions & 0 deletions README.md
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> &gt;</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
3 changes: 0 additions & 3 deletions README.rdoc

This file was deleted.

17 changes: 9 additions & 8 deletions buoy.gemspec → buoys.gemspec
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
6 changes: 6 additions & 0 deletions gemfiles/Gemfile-rails4.1.x
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: '../'
6 changes: 6 additions & 0 deletions gemfiles/Gemfile-rails4.2.x
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: '../'
6 changes: 6 additions & 0 deletions gemfiles/Gemfile-rails5.0.x
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: '../'
4 changes: 0 additions & 4 deletions lib/buoy.rb

This file was deleted.

22 changes: 22 additions & 0 deletions lib/buoys.rb
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
44 changes: 44 additions & 0 deletions lib/buoys/buoy.rb
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
9 changes: 9 additions & 0 deletions lib/buoys/config.rb
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
31 changes: 31 additions & 0 deletions lib/buoys/helper.rb
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
Loading

0 comments on commit 0c037fa

Please sign in to comment.