breadcrumbs_rails 0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d28a2673f20c576627472cdb98978eccd61e2cf2f2a850cc226bfc60a74110ac
4
- data.tar.gz: b24469f0e3ff01edd282af0c4d39570d5b402010996aae8139fffd6acb63f011
3
+ metadata.gz: 481a041e6639cb0a33b985322c02c98dcc60a496fd528f2cf647406b479057a7
4
+ data.tar.gz: 368657c68d3be4bfd57105a8c6764a7dbad3f13831207c6a4840d0298194663c
5
5
  SHA512:
6
- metadata.gz: 559cf5bbdcb461a721f37d05ba0e4f601f4ee166e09266d19e42b78525738d25b9ba45d97dbafb11bcbf9e59fe7ef9a054640f4eac904610dbe3592675c88590
7
- data.tar.gz: 0d6f7a5b9232c82e5dc037a214b9631a702b2b0e8690463af0eed5f09800f416582c02e7fafabb89c42cb4647957cac65346cb7d648ab1903a316b4007e6c108
6
+ metadata.gz: b7828dc371a46f67aacda7a74d93854603791f4afec2f6ce6ac1270003b9e34ddc5491439530fa7fbe899b58f3307b5bc275ce97c9fc01cea0f17835e07af20c
7
+ data.tar.gz: 19553a7b9208d91ee61a86a77097ede252c3e9e843c43f089e2f86ce7ba4a8a25cb0812ad397efef1279e4fa90f421d81dbe7e3b8747daaaeceec87accf07671
data/.gitignore CHANGED
@@ -1,3 +1,7 @@
1
+ # IDE
1
2
  .idea/
2
- .bundle
3
- Gemfile.lock
3
+ .atom/
4
+ .vscode/
5
+
6
+ # Gem builds
7
+ breadcrumbs_rails-*.gem
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,143 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ breadcrumbs_rails (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (6.0.3.4)
10
+ actionpack (= 6.0.3.4)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailbox (6.0.3.4)
14
+ actionpack (= 6.0.3.4)
15
+ activejob (= 6.0.3.4)
16
+ activerecord (= 6.0.3.4)
17
+ activestorage (= 6.0.3.4)
18
+ activesupport (= 6.0.3.4)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.3.4)
21
+ actionpack (= 6.0.3.4)
22
+ actionview (= 6.0.3.4)
23
+ activejob (= 6.0.3.4)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (6.0.3.4)
27
+ actionview (= 6.0.3.4)
28
+ activesupport (= 6.0.3.4)
29
+ rack (~> 2.0, >= 2.0.8)
30
+ rack-test (>= 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.3.4)
34
+ actionpack (= 6.0.3.4)
35
+ activerecord (= 6.0.3.4)
36
+ activestorage (= 6.0.3.4)
37
+ activesupport (= 6.0.3.4)
38
+ nokogiri (>= 1.8.5)
39
+ actionview (6.0.3.4)
40
+ activesupport (= 6.0.3.4)
41
+ builder (~> 3.1)
42
+ erubi (~> 1.4)
43
+ rails-dom-testing (~> 2.0)
44
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.3.4)
46
+ activesupport (= 6.0.3.4)
47
+ globalid (>= 0.3.6)
48
+ activemodel (6.0.3.4)
49
+ activesupport (= 6.0.3.4)
50
+ activerecord (6.0.3.4)
51
+ activemodel (= 6.0.3.4)
52
+ activesupport (= 6.0.3.4)
53
+ activestorage (6.0.3.4)
54
+ actionpack (= 6.0.3.4)
55
+ activejob (= 6.0.3.4)
56
+ activerecord (= 6.0.3.4)
57
+ marcel (~> 0.3.1)
58
+ activesupport (6.0.3.4)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ zeitwerk (~> 2.2, >= 2.2.2)
64
+ builder (3.2.4)
65
+ concurrent-ruby (1.1.7)
66
+ crass (1.0.6)
67
+ erubi (1.10.0)
68
+ globalid (0.4.2)
69
+ activesupport (>= 4.2.0)
70
+ i18n (1.8.5)
71
+ concurrent-ruby (~> 1.0)
72
+ loofah (2.8.0)
73
+ crass (~> 1.0.2)
74
+ nokogiri (>= 1.5.9)
75
+ mail (2.7.1)
76
+ mini_mime (>= 0.1.1)
77
+ marcel (0.3.3)
78
+ mimemagic (~> 0.3.2)
79
+ method_source (1.0.0)
80
+ mimemagic (0.3.5)
81
+ mini_mime (1.0.2)
82
+ mini_portile2 (2.4.0)
83
+ minitest (5.14.2)
84
+ nio4r (2.5.4)
85
+ nokogiri (1.10.10)
86
+ mini_portile2 (~> 2.4.0)
87
+ rack (2.2.3)
88
+ rack-test (1.1.0)
89
+ rack (>= 1.0, < 3)
90
+ rails (6.0.3.4)
91
+ actioncable (= 6.0.3.4)
92
+ actionmailbox (= 6.0.3.4)
93
+ actionmailer (= 6.0.3.4)
94
+ actionpack (= 6.0.3.4)
95
+ actiontext (= 6.0.3.4)
96
+ actionview (= 6.0.3.4)
97
+ activejob (= 6.0.3.4)
98
+ activemodel (= 6.0.3.4)
99
+ activerecord (= 6.0.3.4)
100
+ activestorage (= 6.0.3.4)
101
+ activesupport (= 6.0.3.4)
102
+ bundler (>= 1.3.0)
103
+ railties (= 6.0.3.4)
104
+ sprockets-rails (>= 2.0.0)
105
+ rails-dom-testing (2.0.3)
106
+ activesupport (>= 4.2.0)
107
+ nokogiri (>= 1.6)
108
+ rails-html-sanitizer (1.3.0)
109
+ loofah (~> 2.3)
110
+ railties (6.0.3.4)
111
+ actionpack (= 6.0.3.4)
112
+ activesupport (= 6.0.3.4)
113
+ method_source
114
+ rake (>= 0.8.7)
115
+ thor (>= 0.20.3, < 2.0)
116
+ rake (13.0.1)
117
+ sprockets (4.0.2)
118
+ concurrent-ruby (~> 1.0)
119
+ rack (> 1, < 3)
120
+ sprockets-rails (3.2.2)
121
+ actionpack (>= 4.0)
122
+ activesupport (>= 4.0)
123
+ sprockets (>= 3.0.0)
124
+ thor (1.0.1)
125
+ thread_safe (0.3.6)
126
+ tzinfo (1.2.8)
127
+ thread_safe (~> 0.1)
128
+ websocket-driver (0.7.3)
129
+ websocket-extensions (>= 0.1.0)
130
+ websocket-extensions (0.1.5)
131
+ zeitwerk (2.4.1)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ breadcrumbs_rails!
138
+ bundler
139
+ rails (>= 3.0)
140
+ rake
141
+
142
+ BUNDLED WITH
143
+ 2.1.2
@@ -1,24 +1,26 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
1
+ $:.push File.expand_path('../lib', __FILE__)
3
2
  require 'breadcrumbs_rails/version'
4
3
 
5
- Gem::Specification.new do |spec|
6
- spec.name = 'breadcrumbs_rails'
7
- spec.version = BreadcrumbsRails::VERSION
8
- spec.authors = %w(EdCordata)
9
- spec.summary = %q{Rails breadcrumbs gem}
10
- spec.description = %q{Rails breadcrumbs gem}
11
- spec.homepage = 'https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails'
12
- spec.metadata = {
4
+ Gem::Specification.new do |s|
5
+ s.name = 'breadcrumbs_rails'
6
+ s.version = BreadcrumbsRails::VERSION.dup
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = 'EdCordata'
9
+ s.description = 'Rails breadcrumbs gem'
10
+ s.summary = 'Rails breadcrumbs gem'
11
+ s.licenses = ['CC BY 4.0']
12
+ s.require_paths = %w(lib)
13
+ s.files = `git ls-files`.split("\n")
14
+ s.homepage = 'https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails'
15
+ s.require_paths = ['lib']
16
+ s.required_ruby_version = '>= 1.9.3'
17
+ s.rubygems_version = '1.6.2'
18
+ s.metadata = {
13
19
  'documentation_uri' => 'https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails/blob/master/readme.md',
14
20
  'source_code_uri' => 'https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails',
15
21
  'bug_tracker_uri' => 'https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails/issues'
16
22
  }
17
- spec.license = 'CC BY 4.0'
18
- spec.files = `git ls-files`.split($/)
19
- spec.require_paths = %w(lib)
20
- spec.required_ruby_version = '>= 1.9.3'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'rails', '>= 3.0'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'rails', '>= 3.0'
24
26
  end
@@ -0,0 +1,158 @@
1
+ module BreadcrumbsRails
2
+ module ActionController
3
+ extend ActiveSupport::Concern
4
+
5
+
6
+ # -----------------------------------------------------------
7
+ included do |base|
8
+ extend ClassMethods
9
+ helper HelperMethods
10
+
11
+ helper_method :add_breadcrumb, :breadcrumbs_gem
12
+
13
+ unless base.respond_to?(:before_action)
14
+ base.alias_method :before_action, :before_filter
15
+ end
16
+ end
17
+ # -----------------------------------------------------------
18
+
19
+
20
+ protected
21
+
22
+
23
+ # -----------------------------------------------------------
24
+ def add_breadcrumb(name, options = {})
25
+ url_helpers = Rails.application.routes.url_helpers
26
+
27
+ if options[:path]
28
+ options[:path] = if url_helpers.methods.include?(options[:path])
29
+ url_helpers.send(options[:path])
30
+ else
31
+ options[:path]
32
+ end
33
+ end
34
+
35
+ self.breadcrumbs_gem[:breadcrumbs] << {
36
+ name: name,
37
+ path: options[:path].to_s,
38
+ params: options[:params] || {},
39
+ title: options[:title],
40
+ html_safe: options[:html_safe] == true
41
+ }
42
+
43
+ self.breadcrumbs_gem[:localize] = options[:localize] == true unless options[:localize].nil?
44
+ self.breadcrumbs_gem[:html_safe] = options[:html_safe] == true unless options[:html_safe].nil?
45
+ end
46
+
47
+ def breadcrumbs_gem
48
+ @breadcrumbs_gem ||= { breadcrumbs: [], scope: nil, localize: false }
49
+ end
50
+ # -----------------------------------------------------------
51
+
52
+
53
+ # Class Methods
54
+ # -----------------------------------------------------------
55
+ module ClassMethods
56
+
57
+ def add_breadcrumb(name, options = {})
58
+ before_action(options) do |controller|
59
+ controller.send(:add_breadcrumb, name, options)
60
+ end
61
+ end
62
+
63
+ end
64
+ # -----------------------------------------------------------
65
+
66
+
67
+ # Helper Methods
68
+ # -----------------------------------------------------------
69
+ module HelperMethods
70
+
71
+
72
+ def render_breadcrumbs_title(default = nil)
73
+ return default if breadcrumbs_gem[:breadcrumbs].last[:title].nil?
74
+ return '' if breadcrumbs_gem[:breadcrumbs].last[:title].to_s.blank?
75
+
76
+ if breadcrumbs_gem[:localize]
77
+ I18n.t(breadcrumbs_gem[:breadcrumbs].last[:title])
78
+ else
79
+ breadcrumbs_gem[:breadcrumbs].last[:title]
80
+ end
81
+ end
82
+
83
+
84
+ def render_breadcrumbs(options = {}, &block)
85
+ format = (options[:format] || :html).to_sym
86
+
87
+ if block_given?
88
+ yield(breadcrumbs_gem)
89
+ else
90
+
91
+ case format
92
+
93
+ when :html
94
+ content_tag(:ul) do
95
+ breadcrumbs_gem[:breadcrumbs].map do |breadcrumb|
96
+ concat content_tag(:li, breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb))
97
+ end
98
+ end
99
+
100
+ when :bootstrap
101
+ content_tag(:ul, class: 'pagination') do
102
+ breadcrumbs_gem[:breadcrumbs].map do |breadcrumb|
103
+ concat content_tag(:li, breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb))
104
+ end
105
+ end
106
+
107
+ when :inspinia
108
+ html = ''
109
+ html << '<div class="row wrapper border-bottom white-bg page-heading">'
110
+ html << ' <div class="col-lg-9">'
111
+ html << (render_breadcrumbs_title ? "<h2>#{render_breadcrumbs_title}</h2>" : '<br/>')
112
+ html << ' <ol class="breadcrumb">'
113
+
114
+ breadcrumbs_gem[:breadcrumbs].each_with_index do |breadcrumb, index|
115
+ if (index + 1) == breadcrumbs_gem[:breadcrumbs].length
116
+ html << "<li class='active'><strong>#{breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb)}</strong></li>"
117
+ else
118
+ html << "<li>#{breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb)}</li>"
119
+ end
120
+ end
121
+
122
+ html << ' </ol>'
123
+ html << ' </div>'
124
+ html << '</div>'
125
+ html.html_safe
126
+
127
+ else
128
+ raise "Breadcrumbs-rails: unknown format '#{format.to_s}'"
129
+ end
130
+
131
+ end
132
+ end
133
+
134
+
135
+ private
136
+
137
+
138
+ def breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb)
139
+ return '' if breadcrumb[:name].to_s.blank?
140
+
141
+ name = (breadcrumbs_gem[:localize] ? I18n.t(breadcrumb[:name]) : breadcrumb[:name])
142
+ name = CGI::escapeHTML(name) unless breadcrumb[:html_safe] # escape name as we call html_safe
143
+
144
+ if breadcrumb[:path].to_s.blank?
145
+ name.html_safe
146
+ else
147
+ url = Rails.application.routes.url_helpers.send(breadcrumb[:path].to_s, breadcrumb[:params])
148
+ link_to(name.html_safe, url)
149
+ end
150
+ end
151
+
152
+
153
+ end
154
+ # -----------------------------------------------------------
155
+
156
+
157
+ end
158
+ end
@@ -1,10 +1,11 @@
1
1
  module BreadcrumbsRails
2
-
3
2
  class Railtie < Rails::Railtie
3
+
4
4
  ActiveSupport.on_load(:action_controller) do
5
- views_path = "#{File.dirname(__FILE__)}/../generators/breadcrumbs/templates/app/views"
6
- ::ActionController::Base.append_view_path(views_path)
5
+ ::ActionController::Base.send(:include, BreadcrumbsRails::ActionController)
6
+ views_path = "#{File.dirname(__FILE__)}/../generators/breadcrumbs/templates/app/views/breadcrumbs"
7
+ ::ActionController::Base.prepend_view_path(views_path)
7
8
  end
8
- end
9
9
 
10
+ end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module BreadcrumbsRails
2
- VERSION = '0.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,85 +1,8 @@
1
1
  require 'breadcrumbs_rails/version'
2
+ require 'breadcrumbs_rails/action_controller'
2
3
  require 'breadcrumbs_rails/railtie'
3
- require 'breadcrumbs_rails/breadcrumb'
4
- require 'breadcrumbs_rails/breadcrumbs'
5
4
 
6
5
  module BreadcrumbsRails
7
- extend ActiveSupport::Concern
8
-
9
-
10
- # ----------------------------------------------------------
11
- included do |base|
12
-
13
-
14
- unless base.respond_to?(:before_action)
15
- base.alias_method :before_filter, :before_action
16
- end
17
-
18
-
19
- helper_method :render_breadcrumbs_title, :render_breadcrumbs
20
-
21
-
22
- def add_breadcrumb(name, options = {})
23
- self.breadcrumbs_gem.breadcrumbs << ::BreadcrumbsRails::Breadcrumb.new(
24
- name_string: name,
25
- path_string: options[:path],
26
- locale: options[:locale],
27
- localize: options[:localize],
28
- )
29
-
30
- self.breadcrumbs_gem.localize = options[:localize] if options.has_key?(:localize)
31
- self.breadcrumbs_gem.locale = options[:locale] if options.has_key?(:locale)
32
- self.breadcrumbs_gem.scope = options[:scope] if options.has_key?(:scope)
33
- self.breadcrumbs_gem.title_string = options[:title] if options.has_key?(:title)
34
- end
35
-
36
-
37
- def breadcrumbs_gem
38
- @breadcrumbs_gem ||= ::BreadcrumbsRails::Breadcrumbs.new
39
- end
40
-
41
-
42
- def render_breadcrumbs_title(default = nil)
43
- breadcrumbs_gem.title || default
44
- end
45
-
46
-
47
- def render_breadcrumbs(template: nil, &block)
48
- if block_given?
49
- yield(breadcrumbs_gem)
50
- else
51
-
52
- if template.nil?
53
- partial = 'breadcrumbs/breadcrumbs'
54
- partial = (breadcrumbs_gem.scope + '/' + partial) unless breadcrumbs_gem.scope.nil?
55
- else
56
- partial = "breadcrumbs/#{template}"
57
- end
58
-
59
- partial += '.html'
60
-
61
- render(partial: partial,
62
- locals: { breadcrumbs: breadcrumbs_gem },
63
- handlers: [:erb, :haml])
64
- end
65
- end
66
-
67
-
68
- end
69
- # ----------------------------------------------------------
70
-
71
-
72
- # ----------------------------------------------------------
73
- class_methods do
74
-
75
- def add_breadcrumb(name, options = {})
76
- before_action(options) do |controller|
77
- controller.send(:add_breadcrumb, name, options)
78
- end
79
- end
80
-
81
- end
82
- # ----------------------------------------------------------
83
-
84
-
6
+ NAME = 'Breadcrumbs Rails'
7
+ GEM = 'breadcrumbs_rails'
85
8
  end
data/readme.md CHANGED
@@ -1,47 +1,45 @@
1
- ## Breadcrumbs Rails
1
+ # Breadcrumbs Rails
2
2
 
3
3
  ![Ruby Version](badges/ruby.svg)
4
- ![Ruby Version](badges/rails.svg)
5
4
  [![License](badges/license.svg)](https://creativecommons.org/licenses/by/4.0/)
6
5
 
6
+ Breadcrumbs rails is easy way to create breadcrumbs from controllers and render them in view. This gem also
7
+ includes functionality to easily change title.
7
8
 
8
- <br/>
9
-
10
-
11
- #### Installation
9
+ ### Installation
12
10
 
13
11
  As usual, add to Gemfile:
14
12
  ```ruby
15
13
  gem 'breadcrumbs_rails'
16
14
  ```
17
15
 
18
- Generate config:
16
+ and run:
19
17
  ```bash
20
- rails g breadcrumbs:config
18
+ $ bundle install
21
19
  ```
22
20
 
23
21
 
24
- <br/>
22
+ ### Introduction
23
+
24
+ Syntax is `add_breadcrumb(name, options)`
25
+ Available options:
26
+ * `html_safe` - (type: boolean, default: false) - specifies if title is html safe and shouldn't be escaped
27
+ * `:path` - (type: string, default: nil) - link path as string. It must be a string, not symbol
28
+ * `:params` - (type: hash, default: {}) - params to pass to `:path`
29
+ * `:title` - (type: string, default: nil) - title for `:render_breadcrumbs_title` method
30
+
25
31
 
26
32
 
27
- #### Usage:
33
+ ### Usage
28
34
 
29
35
  In controllers
30
36
  ```ruby
31
37
  class ApplicationController < ActionController::Base
32
- include BreadcrumbsRails
33
-
34
- # non-required attributes:
35
- # * path - if not specified, item will be text, instead of link. Possible STRING values: '/', 'root_path'
36
- # * scope - views scope, in case you want different breadcrumbs for different namespaces, like 'admin'
37
- # * views_title - only for inspinia template. This is title above breadcrumbs.
38
- # * template - template of views to use: 'html', 'bootstrap', 'inspinia' (only if not using custom views).
39
- # Note that, if this argument is passed, gems views will be used.
40
- add_breadcrumb 'views.home', path: 'root_path', title: 'Home', scope: 'views.admin', localize: true
38
+ add_breadcrumb 'Home', path: 'root_path', params: { locale: 'en' }
41
39
  end
42
40
 
43
41
  class UsersController < ApplicationController
44
- add_breadcrumb 'Users', path: 'users_path', title: 'Users'
42
+ add_breadcrumb 'Users', path: 'users_path', params: { locale: 'en' }, title: 'Users'
45
43
 
46
44
  def edit
47
45
  add_breadcrumb('User')
@@ -49,66 +47,36 @@ class UsersController < ApplicationController
49
47
  end
50
48
  ```
51
49
 
52
- To use `title` functionality:
53
- ```haml
54
- %title= render_breadcrumbs_title
55
- ```
56
-
57
- Using gem's views
58
- ```haml
59
- = render_breadcrumbs
50
+ If you want to use translations, do it like so:
51
+ ```ruby
52
+ class ApplicationController < ActionController::Base
53
+ add_breadcrumb 'links.home', path: 'root_path', params: { locale: 'en' }, title: '', localize: true # Only name is required
54
+ end
60
55
 
61
- # or with specific template
62
- = render_breadcrumbs(template: 'bootstrap') # default: 'html'; available: 'html', 'bootstrap', 'inspinia'
56
+ class UsersController < ApplicationController
57
+ add_breadcrumb 'links.users', path: 'users_path', params: { locale: 'en' }, title: 'Users'
58
+
59
+ def edit
60
+ add_breadcrumb('links.user')
61
+ end
62
+ end
63
63
  ```
64
64
 
65
- Or creating custom:
65
+ ### Rendering breadcrumbs
66
+ Default format is `:html`. Available: `:html`, `:bootstrap`, `:inspinia`.
66
67
  ```haml
67
- - render_breadcrumbs do |breadcrumbs|
68
- - breadcrumbs.breadcrumbs.each do |breadcrumb|
69
- %li= link_to_if breadcrumb.path, breadcrumb.name, breadcrumb.path
68
+ = render_breadcrumbs(format: :html)
70
69
  ```
71
70
 
72
- Available methods:
71
+ Or by using block:
73
72
  ```haml
74
- - render_breadcrumbs do |breadcrumbs|
75
-
76
- - breadcrumbs.scope # current scope
77
- - breadcrumbs.format # current format
78
-
79
- breadcrumb.localize # boolean if should localize title
80
- breadcrumb.locale # current locale
81
-
82
- - breadcrumbs.title_string # string, provided in admin panel
83
- - breadcrumbs.title # string or translation of title, provided in admin panel
84
-
85
- - breadcrumbs.breadcrumbs.each do |breadcrumb|
86
-
87
- breadcrumb.localize # boolean if should localize name
88
- breadcrumb.locale # current locale
89
-
90
- breadcrumb.name_string # string, provided in admin panel
91
- breadcrumb.name # string or translation of string, provided in admin panel
92
-
93
- breadcrumb.path_path # path string, provided in admin panel
94
- breadcrumb.path # path string or url, provided in admin
73
+ - render_breadcrumbs do |renderer|
74
+ - renderer[:breadcrumbs].each do |breadcrumb|
75
+ %li= link_to_if breadcrumb[:path], breadcrumb[:name], breadcrumb[:path]
95
76
  ```
96
77
 
97
-
98
- <br/>
99
-
100
-
101
-
102
- #### Generate views
103
-
104
- You can also specify only one format (`haml`, `erb.html`), by adding `--format` parameter:
105
- ```bash
106
- rails g breadcrumbs:views haml --format haml
107
- rails g breadcrumbs:views haml --format erb
108
-
109
- rails g breadcrumbs:views inspinia --format haml
110
- rails g breadcrumbs:views inspinia --format erb
111
-
112
- rails g breadcrumbs:views bootstrap --format haml
113
- rails g breadcrumbs:views bootstrap --format erb
78
+ ### To use `title` functionality:
79
+ ```haml
80
+ %html
81
+ %title= render_breadcrumbs_title
114
82
  ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadcrumbs_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - EdCordata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-28 00:00:00.000000000 Z
11
+ date: 2020-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -60,24 +60,14 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - ".gitignore"
62
62
  - Gemfile
63
+ - Gemfile.lock
63
64
  - badges/license.svg
64
- - badges/rails.svg
65
65
  - badges/ruby.svg
66
66
  - breadcrumbs_rails.gemspec
67
67
  - lib/breadcrumbs_rails.rb
68
- - lib/breadcrumbs_rails/breadcrumb.rb
69
- - lib/breadcrumbs_rails/breadcrumbs.rb
68
+ - lib/breadcrumbs_rails/action_controller.rb
70
69
  - lib/breadcrumbs_rails/railtie.rb
71
70
  - lib/breadcrumbs_rails/version.rb
72
- - lib/generators/breadcrumbs/config_generator.rb
73
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_bootstrap.html.erb
74
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_bootstrap.html.haml
75
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_html.html.erb
76
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_html.html.haml
77
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_inspinia.html.erb
78
- - lib/generators/breadcrumbs/templates/app/views/breadcrumbs/_inspinia.html.haml
79
- - lib/generators/breadcrumbs/templates/config/initializers/breadcrumbs_config.rb
80
- - lib/generators/breadcrumbs/views_generator.rb
81
71
  - readme.md
82
72
  homepage: https://github.com/EdCordata-Ruby-Gems/breadcrumbs_rails
83
73
  licenses:
@@ -101,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
91
  - !ruby/object:Gem::Version
102
92
  version: '0'
103
93
  requirements: []
104
- rubygems_version: 3.2.22
94
+ rubygems_version: 3.1.2
105
95
  signing_key:
106
96
  specification_version: 4
107
97
  summary: Rails breadcrumbs gem
data/badges/rails.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="20" role="img" aria-label="rails: 3.0+"><title>rails: 3.0+</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="70" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="33" height="20" fill="#555"/><rect x="33" width="37" height="20" fill="#fe7d37"/><rect width="70" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">rails</text><text x="175" y="140" transform="scale(.1)" fill="#fff" textLength="230">rails</text><text aria-hidden="true" x="505" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">3.0+</text><text x="505" y="140" transform="scale(.1)" fill="#fff" textLength="270">3.0+</text></g></svg>
@@ -1,46 +0,0 @@
1
- module BreadcrumbsRails
2
- class Breadcrumb
3
-
4
-
5
- attr_accessor :name, :name_string,
6
- :path, :path_string,
7
- :localize, :locale
8
-
9
-
10
- def initialize(name_string: nil, path_string: nil, localize: nil, locale: nil)
11
- @locale = locale || 'en'
12
- @localize = localize || false
13
-
14
- @name_string = name_string
15
- @name = generate_name
16
-
17
- @path_string = path_string
18
- @path = generate_path
19
- end
20
-
21
-
22
- private
23
-
24
-
25
- def generate_name
26
- if @localize
27
- ::I18n.t(@name_string, locale: @locale, default: @name_string)
28
- else
29
- @name_string
30
- end
31
- end
32
-
33
-
34
- def generate_path
35
- url_helpers = ::Rails.application.routes.url_helpers
36
-
37
- if url_helpers.methods.include?(@path_string.to_s.to_sym)
38
- url_helpers.send(@path_string)
39
- else
40
- @path_string
41
- end
42
- end
43
-
44
-
45
- end
46
- end
@@ -1,37 +0,0 @@
1
- module BreadcrumbsRails
2
- class Breadcrumbs
3
-
4
- attr_accessor :breadcrumbs,
5
- :scope, :format,
6
- :title, :title_string,
7
- :localize, :locale
8
-
9
- def initialize(breadcrumbs: [], title_string: nil, scope: nil, format: nil, localize: nil, locale: nil)
10
- @breadcrumbs = breadcrumbs || []
11
- @format = format || 'html'
12
- @scope = scope
13
-
14
- @title_string = title_string
15
- @title = generate_title
16
-
17
- @localize = localize || false
18
- @locale = locale || 'en'
19
- end
20
-
21
- def title_string=(title_string)
22
- @title_string = title_string
23
- @title = generate_title
24
- end
25
-
26
- private
27
-
28
- def generate_title
29
- if @localize
30
- ::I18n.t(@title_string, locale: @locale, default: @title_string)
31
- else
32
- @title_string
33
- end
34
- end
35
-
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- module Breadcrumbs
2
- module Generators
3
- class ConfigGenerator < Rails::Generators::Base
4
- source_root ::File.expand_path(::File.join(::File.dirname(__FILE__), 'templates/config/initializers'))
5
-
6
- def copy_config_file
7
- template 'breadcrumbs_config.rb', 'config/initializers/breadcrumbs.rb'
8
- end
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- <% render_breadcrumbs.each do |breadcrumbs| %>
2
- <ul class="pagination">
3
- <% breadcrumbs.breadcrumbs.each do |breadcrumb| %>
4
- <li>
5
- <% if breadcrumb.path %>
6
- <%= link_to breadcrumb.name, breadcrumb.path %>
7
- <% else %>
8
- <%= breadcrumb.name %>
9
- <% end %>
10
- </li>
11
- <% end %>
12
- </ul>
13
- <% end %>
@@ -1,8 +0,0 @@
1
- - render_breadcrumbs.each do |breadcrumbs|
2
- %ul.pagination
3
- - breadcrumbs.breadcrumbs.each do |breadcrumb|
4
- %li
5
- - if breadcrumb.path
6
- = link_to breadcrumb.name, breadcrumb.path
7
- - else
8
- = breadcrumb.name
@@ -1,13 +0,0 @@
1
- <% render_breadcrumbs.each do |breadcrumbs| %>
2
- <ul>
3
- <% breadcrumbs.breadcrumbs.each do |breadcrumb| %>
4
- <li>
5
- <% if breadcrumb.path %>
6
- <%= link_to breadcrumb.name, breadcrumb.path %>
7
- <% else %>
8
- <%= breadcrumb.name %>
9
- <% end %>
10
- </li>
11
- <% end %>
12
- </ul>
13
- <% end %>
@@ -1,8 +0,0 @@
1
- - render_breadcrumbs.each do |breadcrumbs|
2
- %ul
3
- - breadcrumbs.breadcrumbs.each do |breadcrumb|
4
- %li
5
- - if breadcrumb.path
6
- = link_to breadcrumb.name, breadcrumb.path
7
- - else
8
- = breadcrumb.name
@@ -1,21 +0,0 @@
1
- <% render_breadcrumbs do |breadcrumbs| %>
2
- <div class="row wrapper border-bottom white-bg page-heading">
3
- <div class="col-lg-10">
4
-
5
- <h2><%= breadcrumbs.title %></h2>
6
-
7
- <ol class="breadcrumb">
8
- <% breadcrumbs.breadcrumbs.each do |breadcrumb| %>
9
- <li>
10
- <% if breadcrumb.path %>
11
- <%= link_to breadcrumb.name, breadcrumb.path %>
12
- <% else %>
13
- <%= breadcrumb.name %>
14
- <% end %>
15
- </li>
16
- <% end %>
17
- </ol>
18
-
19
- </div>
20
- </div>
21
- <% end %>
@@ -1,13 +0,0 @@
1
- - render_breadcrumbs do |breadcrumbs|
2
- .row.wrapper.border-bottom.white-bg.page-heading
3
- .col-lg-10
4
-
5
- %h2= breadcrumbs.title
6
-
7
- %ol.breadcrumb
8
- - breadcrumbs.breadcrumbs.each do |breadcrumb|
9
- %li
10
- - if breadcrumb.path
11
- = link_to breadcrumb.name, breadcrumb.path
12
- - else
13
- = breadcrumb.name
@@ -1 +0,0 @@
1
- # breadcrumbs config coming soon
@@ -1,22 +0,0 @@
1
- module Breadcrumbs
2
- module Generators
3
- class ViewsGenerator < ::Rails::Generators::NamedBase
4
- source_root ::File.expand_path(::File.join(::File.dirname(__FILE__), 'templates/app/views/breadcrumbs'))
5
- desc 'Template engine for the views. Available options are "erb", "haml".'
6
-
7
- class_option :format, type: :string, default: 'all'
8
-
9
- def copy_default_views
10
- case options['format'].try(:to_s).try(:downcase)
11
- when 'haml'
12
- copy_file("_#{@name}.html.haml", 'app/views/breadcrumbs/_breadcrumbs.html.haml')
13
- when 'erb'
14
- copy_file("_#{@name}.html.erb", 'app/views/breadcrumbs/_breadcrumbs.html.erb')
15
- else
16
- copy_file("_#{@name}.html.haml", 'app/views/breadcrumbs/_breadcrumbs.html.haml')
17
- copy_file("_#{@name}.html.erb", 'app/views/breadcrumbs/_breadcrumbs.html.erb')
18
- end
19
- end
20
- end
21
- end
22
- end