buoys 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328e475c660faef4b8c35b25ffabefcd2097dbb5
4
- data.tar.gz: f7aa9ab50d8ead9ffcb2127047c70806438d078e
3
+ metadata.gz: 3e78176edf374e239e8edc82b58967bd7c8af0db
4
+ data.tar.gz: 5bc190247b5979b6ceb386efa33e95cbf0b5f963
5
5
  SHA512:
6
- metadata.gz: 3617a33b4bc75b7c779ccfa00af1eefd394a9293aa651c32b11576c9a008ec312325f30609b1df83d90152440490fc801d15082d9ddd892fd6ea24cf00140e3d
7
- data.tar.gz: 31c46adae6c5d0eb145f383f61cdbe69c4866c5e7e61d32a12d0e2a7bb2ae1084a330b15699ce90e0c1e45f95711d94948d2691004bb85877fbbb89d291317c8
6
+ metadata.gz: 980a48fac48ff04a5926fc8fe7092f99569e84004159114d039c7b65622f59c47fc046ea4ae7ded09c47676781133d08b2c2aceb7d7e29ecffa04a0c994ffa03
7
+ data.tar.gz: 86540406c985a7c063d056a78a9af5b566c74c7cd0bce44c3296fa963251a4d6974ca1e55d2ccb7977932f00d1c035d1a73507758f598a6cf333b0144862fdaf
data/README.md CHANGED
@@ -28,8 +28,16 @@ Start by generating configuration and example files.
28
28
  ```ruby
29
29
  $ bin/rails g buoys:install
30
30
  create config/locale/buoys.en.yml
31
+ create config/buoys/breadcrumbs.rb
31
32
  create app/views/breadcrumbs/_buoys.html.erb
33
+ ```
34
+
35
+ You can use `--template haml` and `--template slim` options.
36
+ ```ruby
37
+ $ bin/rails g buoys:install --template haml
38
+ create config/locale/buoys.en.yml
32
39
  create config/buoys/breadcrumbs.rb
40
+ create app/views/breadcrumbs/_buoys.html.haml
33
41
  ```
34
42
 
35
43
  Then, in `config/buoys/breadcrumbs.rb`
data/Rakefile CHANGED
@@ -14,11 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
-
21
-
22
17
  Bundler::GemHelper.install_tasks
23
18
 
24
19
  require 'rake/testtask'
@@ -30,5 +25,4 @@ Rake::TestTask.new(:test) do |t|
30
25
  t.verbose = false
31
26
  end
32
27
 
33
-
34
28
  task default: :test
data/lib/buoys/buoy.rb CHANGED
@@ -14,8 +14,9 @@ module Buoys
14
14
  block = Buoys::Loader.buoys[key]
15
15
  raise ArgumentError, "Buoys :#{key} is not found" unless block
16
16
 
17
- @key, @context = key, context
18
- instance_exec *args, &block
17
+ @key = key
18
+ @context = context
19
+ instance_exec(*args, &block)
19
20
  end
20
21
 
21
22
  def link(key, *args)
@@ -35,7 +36,7 @@ module Buoys
35
36
  def pre_buoy(key, *args)
36
37
  @previous = Buoys::Buoy.new(context, key, args)
37
38
  end
38
- alias_method :parent, :pre_buoy
39
+ alias parent pre_buoy
39
40
 
40
41
  def method_missing(method, *args, &block)
41
42
  context.send(method, *args, &block)
data/lib/buoys/helper.rb CHANGED
@@ -6,7 +6,7 @@ module Buoys
6
6
  def buoy(key, *args)
7
7
  @_buoys_renderer = Buoys::Renderer.new(self, key, *args)
8
8
  end
9
- alias_method :breadcrumb, :buoy
9
+ alias breadcrumb buoy
10
10
 
11
11
  # <% buoys.tap do |links| %>
12
12
  # <% if links.any? %>
@@ -22,7 +22,7 @@ module Buoys
22
22
  def buoys
23
23
  buoys_renderer.render
24
24
  end
25
- alias_method :breadcrumbs, :buoys
25
+ alias breadcrumbs buoys
26
26
 
27
27
  def buoys_renderer
28
28
  @_buoys_renderer ||= Buoys::Renderer.new(self, nil)
data/lib/buoys/link.rb CHANGED
@@ -5,22 +5,23 @@ module Buoys
5
5
 
6
6
  CONFIG = {
7
7
  current_class: (Buoys::Config.current_class || 'active'),
8
- link_current: (Buoys::Config.link_current || false),
8
+ link_current: (Buoys::Config.link_current || false)
9
9
  }.with_indifferent_access
10
10
 
11
11
  def initialize(text, url, options)
12
12
  @options_for_config, @options = extract_options_and_config(options)
13
- @text, @_url = text, url
13
+ @text = text
14
+ @_url = url
14
15
  @current = false
15
16
  end
16
17
 
17
18
  def mark_as_current!
18
- options.merge!(class: config[:current_class])
19
+ options[:class] = config[:current_class]
19
20
  @current = true
20
21
  end
21
22
 
22
23
  def current?
23
- !!@current
24
+ @current
24
25
  end
25
26
 
26
27
  def url
@@ -39,8 +40,8 @@ module Buoys
39
40
  CONFIG.merge(options_for_config)
40
41
  end
41
42
 
42
- def extract_options_and_config(_options)
43
- options = _options.with_indifferent_access
43
+ def extract_options_and_config(opts)
44
+ options = opts.with_indifferent_access
44
45
  config = (options.keys & CONFIG.keys).each_with_object({}) {|key, hash|
45
46
  hash[key] = options.delete(key)
46
47
  }
data/lib/buoys/loader.rb CHANGED
@@ -13,23 +13,37 @@ module Buoys
13
13
  def buoy(key, &block)
14
14
  buoys[key] = block
15
15
  end
16
- alias_method :crumb, :buoy
16
+ alias crumb buoy
17
17
 
18
18
  def buoys
19
19
  @buoys ||= {}
20
20
  end
21
21
 
22
+ def loaded_times
23
+ @loaded_times ||= []
24
+ end
25
+
22
26
  def load_buoys_files
27
+ return unless need_reload?
28
+
23
29
  buoys.clear
30
+ loaded_times.clear
24
31
 
25
32
  buoy_files.each do |file|
26
33
  instance_eval open(file).read, file
34
+ loaded_times << File.mtime(file)
27
35
  end
28
36
  end
29
37
 
30
38
  def buoy_files
31
39
  Dir[*Buoys.buoy_file_paths]
32
40
  end
41
+
42
+ def need_reload?
43
+ return true if buoys.empty?
44
+
45
+ Rails.env.development? && loaded_times != buoy_files.map {|f| File.mtime(f) }
46
+ end
33
47
  end
34
48
  end
35
49
  end
data/lib/buoys/railtie.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Buoys
2
2
  class Railtie < ::Rails::Railtie
3
- initializer 'buoys' do |_app|
3
+ initializer 'buoys' do
4
4
  ActiveSupport.on_load(:action_view) do
5
5
  ActionView::Base.send :include, Buoys::Helper
6
6
  end
@@ -1,11 +1,11 @@
1
1
  module Buoys
2
2
  class Renderer
3
3
  def initialize(context, key, *args)
4
- @context, @key, @args = context, key, args
4
+ @context = context
5
+ @key = key
6
+ @args = args
5
7
 
6
- if Rails.env.development? || Buoys::Loader.buoys.keys.empty?
7
- Buoys::Loader.load_buoys_files
8
- end
8
+ Buoys::Loader.load_buoys_files
9
9
  end
10
10
 
11
11
  def render
@@ -20,7 +20,7 @@ module Buoys
20
20
  def build_links(buoy)
21
21
  links = buoy.links.dup
22
22
 
23
- links.unshift *collect_previous_links(buoy)
23
+ links.unshift(*collect_previous_links(buoy))
24
24
  links.last.mark_as_current!
25
25
 
26
26
  links
@@ -29,8 +29,10 @@ module Buoys
29
29
  def collect_previous_links(buoy)
30
30
  links = []
31
31
 
32
- while buoy = buoy.previous
33
- links.unshift *buoy.links
32
+ buoy = buoy.previous
33
+ while buoy
34
+ links.unshift(*buoy.links)
35
+ buoy = buoy.previous
34
36
  end
35
37
 
36
38
  links
data/lib/buoys/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Buoys
2
- VERSION = "0.2.0"
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -4,10 +4,17 @@ module Buoys
4
4
  class InstallGenerator < Rails::Generators::Base
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
 
7
+ class_option :template
8
+
7
9
  def create_files
8
10
  copy_file 'buoys.en.yml', 'config/locales/buoys.en.yml'
9
- copy_file '_buoys.html.erb', 'app/views/breadcrumbs/_buoys.html.erb'
10
11
  copy_file 'breadcrumbs.rb', 'config/buoys/breadcrumbs.rb'
12
+
13
+ if %(haml slim).include?(template_type = options[:template])
14
+ copy_file "_buoys.html.#{template_type}", "app/views/breadcrumbs/_buoys.html.#{template_type}"
15
+ else
16
+ copy_file '_buoys.html.erb', 'app/views/breadcrumbs/_buoys.html.erb'
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -0,0 +1,9 @@
1
+ - if buoys.any?
2
+ %ol.breadcrumb
3
+ - buoys.each do |link|
4
+ %li
5
+ - # if `link.current?` is true, link.options includes {class: 'current'}.
6
+ - if link.current?
7
+ %span= link.text
8
+ - else
9
+ = link_to link.text, link.url, link.options
@@ -0,0 +1,10 @@
1
+ - if buoys.any?
2
+ ol.breadcrumb
3
+ - buoys.each do |link|
4
+ li
5
+ - # if `link.current?` is true, link.options includes {class: 'current'}.
6
+ - if link.current?
7
+ span
8
+ = link.text
9
+ - else
10
+ = link_to link.text, link.url, link.options
@@ -9,35 +9,99 @@ class BuoysHelerTest < ActionView::TestCase
9
9
  buoy :account
10
10
  html = render('breadcrumbs/buoys').gsub(/[[:space:]]{2,}|\n/, '')
11
11
 
12
- assert_dom_equal %{<ul><li><a class="active" href=""><span>Account</span></a></li></ul>}, html
12
+ assert_dom_equal %(<ul><li><a class="active" href=""><span>Account</span></a></li></ul>), html
13
13
  end
14
14
 
15
15
  test '.buoy (not only active)' do
16
16
  buoy :history
17
17
  html = render('breadcrumbs/buoys').gsub(/[[:space:]]{2,}|\n/, '')
18
+ expected_html =
19
+ %(
20
+ <ul>
21
+ <li>
22
+ <a class="hover" href="/about">
23
+ <span>about</span>
24
+ </a>
25
+ <span>&gt;</span>
26
+ </li>
27
+ <li>
28
+ <a class="active" href="">
29
+ <span>history</span>
30
+ </a>
31
+ </li>
32
+ </ul>
33
+ ).gsub(/[[:space:]]{2,}|\n/, '')
18
34
 
19
- assert_dom_equal %{<ul><li><a class="hover" href="/about"><span>about</span></a><span>&gt;</span></li><li><a class="active" href=""><span>history</span></a></li></ul>}, html
35
+ assert_dom_equal expected_html, html
20
36
  end
21
37
 
22
38
  test '.buoy (has 2 `link`s in one buoy block)' do
23
39
  breadcrumb :help, true
24
40
  html = render('breadcrumbs/buoys').gsub(/[[:space:]]{2,}|\n/, '')
41
+ expected_html =
42
+ %(
43
+ <ul>
44
+ <li>
45
+ <a class="hover" href="https://example.com/help">
46
+ <span>help</span>
47
+ </a>
48
+ <span>&gt;</span>
49
+ </li>
50
+ <li>
51
+ <a class="active" href="">
52
+ <span>usage</span>
53
+ </a>
54
+ </li>
55
+ </ul>
56
+ ).gsub(/[[:space:]]{2,}|\n/, '')
25
57
 
26
- assert_dom_equal %{<ul><li><a class="hover" href="https://example.com/help"><span>help</span></a><span>&gt;</span></li><li><a class="active" href=""><span>usage</span></a></li></ul>}, html
58
+ assert_dom_equal expected_html, html
27
59
  end
28
60
 
29
61
  test '.buoy (receive multiple arguments)' do
30
62
  breadcrumb :edit_book_author, 1, 2
31
63
  html = render('breadcrumbs/buoys').gsub(/[[:space:]]{2,}|\n/, '')
64
+ expected_html =
65
+ %(
66
+ <ul>
67
+ <li>
68
+ <a class="hover" href="http://example.com/books">
69
+ <span>Books</span>
70
+ </a>
71
+ <span>&gt;</span>
72
+ </li>
73
+ <li>
74
+ <a class="active" href="http://example.com/books/1/authors/2">
75
+ <span>edit-1-2</span>
76
+ </a>
77
+ </li>
78
+ </ul>
79
+ ).gsub(/[[:space:]]{2,}|\n/, '')
32
80
 
33
- assert_dom_equal %{<ul><li><a class="hover" href="http://example.com/books"><span>Books</span></a><span>&gt;</span></li><li><a class="active" href="http://example.com/books/1/authors/2"><span>edit-1-2</span></a></li></ul>}, html
81
+ assert_dom_equal expected_html, html
34
82
  end
35
83
 
36
84
  test ".buoy (has configuration options in link's arguments)" do
37
85
  breadcrumb :show_books, 1
38
86
  html = render('breadcrumbs/buoys').gsub(/[[:space:]]{2,}|\n/, '')
87
+ expected_html =
88
+ %(
89
+ <ul>
90
+ <li>
91
+ <a class="hover" href="http://example.com/books">
92
+ <span>Books</span>
93
+ </a>
94
+ <span>&gt;</span>
95
+ </li>
96
+ <li>
97
+ <a class="active" href="http://example.com/books/1">
98
+ <span>show-1</span>
99
+ </a>
100
+ </li>
101
+ </ul>
102
+ ).gsub(/[[:space:]]{2,}|\n/, '')
39
103
 
40
- assert_dom_equal %{<ul><li><a class="hover" href="http://example.com/books"><span>Books</span></a><span>&gt;</span></li><li><a class="active" href="http://example.com/books/1"><span>show-1</span></a></li></ul>}, html
104
+ assert_dom_equal expected_html, html
41
105
  end
42
106
 
43
107
  test '.buoys (no given key)' do
data/test/buoys_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BuoysTest < ActiveSupport::TestCase
4
- test ".buoy_file_paths" do
4
+ test '.buoy_file_paths' do
5
5
  assert_equal [Rails.root.join('config', 'buoys', '**', '*.rb')], Buoys.buoy_file_paths
6
6
  end
7
7
  end
data/test/test_helper.rb CHANGED
@@ -1,20 +1,22 @@
1
1
  # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
2
+ ENV['RAILS_ENV'] = 'test'
3
3
 
4
- require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
6
- require "rails/test_help"
4
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path('../../test/dummy/db/migrate', __FILE__)]
6
+ require 'rails/test_help'
7
7
 
8
8
  # Filter out Minitest backtrace while allowing backtrace from other libraries
9
9
  # to be shown.
10
10
  Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
11
 
12
12
  # Load support files
13
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
14
+ require f
15
+ end
14
16
 
15
17
  # Load fixtures from the engine
16
18
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
19
+ ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
18
20
  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
21
  ActiveSupport::TestCase.fixtures :all
20
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buoys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - muryoimpl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: deka_eiwakun
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: A Ruby on Rails breadcrumbs plugin.
56
70
  email:
57
71
  - muryoimpl@gmail.com
@@ -73,9 +87,10 @@ files:
73
87
  - lib/buoys/version.rb
74
88
  - lib/generators/buoys/install_generator.rb
75
89
  - lib/generators/buoys/templates/_buoys.html.erb
90
+ - lib/generators/buoys/templates/_buoys.html.haml
91
+ - lib/generators/buoys/templates/_buoys.html.slim
76
92
  - lib/generators/buoys/templates/breadcrumbs.rb
77
93
  - lib/generators/buoys/templates/buoys.en.yml
78
- - lib/tasks/buoy_tasks.rake
79
94
  - test/buoys_buoy_test.rb
80
95
  - test/buoys_helper_test.rb
81
96
  - test/buoys_loader_test.rb
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :buoy do
3
- # # Task goes here
4
- # end