migajas 0.9.0 → 1.0.1

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
- SHA1:
3
- metadata.gz: 2224e900cfa8368a0da6bcd4d8b9fed287645e40
4
- data.tar.gz: 219915ed490c9a9d5d4f7336e91ced8735b366f6
2
+ SHA256:
3
+ metadata.gz: d1c73bd0ffb5454b4eee7071c06cfac143401de7274bd379bf32cdd6209f328f
4
+ data.tar.gz: d7e83df30e99e86080d09e600b6b0d4cb2b76be50e062175d5d4a3799c446e84
5
5
  SHA512:
6
- metadata.gz: 7e00e0bb52756db949d5a02827e466e32e600aaf2164d30eea9be9094c7e145b67937d5bb074f19be4959b97c7a722b66ef9e3cc11e66cbb26a079ff717c6454
7
- data.tar.gz: 39489dd99c8ce61f52c0eba3af37a715f8c64930b5c414546bf33809617e19024d755dc5777865713c59a4c3a03d1a20ea959a19be2118c1ef3cb55969527fc6
6
+ metadata.gz: e5b3b988e648cf63a565c1dc6c417ddbe395cd404f7a83bfb10198351b3eeec22c309468a37c4c203bd6b7998c303a8cd70e06e4750d1da24e1473706ccb0331
7
+ data.tar.gz: fa02e81e1f6dc39ad0ee0ce48b76764c243259d946ebbe591e761907203e0d7995644402108d70d6e074a0fb4c9d63ee89c1a91072441e98b7fc3d0d941b0077
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Migajas
2
2
 
3
- Migajas is a tiny library for adding breadcrumbs to a routing tree framework,
4
- like Cuba or Roda.
3
+ Migajas is a tiny library for adding breadcrumbs to any Rack application. It was
4
+ designed with routing tree frameworks like Cuba or Roda in mind, but works well
5
+ with any Rack-based framework, including Rails.
5
6
 
6
7
  ## Usage
7
8
 
@@ -46,14 +47,59 @@ Then, in the view, go over the `breadcrumbs` list:
46
47
 
47
48
  That's it :)
48
49
 
50
+ ## Rails
51
+
52
+ Start by adding `Migajas::Rails` to your controllers:
53
+
54
+ ``` ruby
55
+ class ApplicationController < ActionController::Base
56
+ include Migajas::Rails
57
+ end
58
+ ```
59
+
60
+ This gives you a `breadcrumbs` method that you can access from your controllers
61
+ and views. The recommended approach is to use action callbacks to add
62
+ breadcrumbs:
63
+
64
+ ``` ruby
65
+ class ApplicationController < ActionController::Base
66
+ include Migajas::Rails
67
+
68
+ before_action { breadcrumbs.add "Home", root_path }
69
+ end
70
+
71
+ class UsersController < ApplicationController
72
+ before_action { breadcrumbs.add "Users", users_path }
73
+ before_action(only: [:show, :edit, :update]) { breadcrumbs.add @user.name, user_path(@user) }
74
+ end
75
+ ```
76
+
77
+ Then, in your layout, you can iterate over the Array:
78
+
79
+ ``` erb
80
+ <ol class="breadcrumbs">
81
+ <% breadcrumbs.each do |crumb| %>
82
+ <%= tag.li class: { active: crumb.current? } do %>
83
+ <%= link_to crumb.name, crumb.url %>
84
+ <% end %>
85
+ <% end %>
86
+ </ol>
87
+ ```
88
+
49
89
  ## Install
50
90
 
51
91
  gem install migajas
52
92
 
93
+ ## Do we need a gem for this?
94
+
95
+ Probably not, but after 2 years of using this code, I got bored of copying and
96
+ pasting it from [a gist](https://gist.github.com/foca/44c9f24a759238fba9fb).
97
+
53
98
  ## What's in a name?
54
99
 
55
100
  `Migajas` is the Spanish word for `breadcrumbs`. It's pronounced like you'd
56
- pronounce `meegahas` in English (or `miˈɣa.xas` if you're a language nerd.)
101
+ pronounce `me-gha-has` in English (`me` as in the word "me", `gha` as in
102
+ "ghast", and `has` as the word "has".)
57
103
 
58
104
  ## License
59
105
 
@@ -1,4 +1,14 @@
1
+ require_relative "migajas/version"
2
+ require_relative "migajas/rails" if defined?(Rails)
3
+
1
4
  module Migajas
5
+ # Public: Reader method to get the Rack env. Override if your framework does
6
+ # not expose an `env` method in the context used when evaluating routing
7
+ # actions or views (such as Rails).
8
+ def migajas_env
9
+ env
10
+ end
11
+
2
12
  # Public: List of breadcrumbs encountered in this request. Add to this list
3
13
  # any breadcrumb as you go through your routing tree in the app:
4
14
  #
@@ -41,7 +51,7 @@ module Migajas
41
51
  #
42
52
  # Returns a Migajas::Trail.
43
53
  def breadcrumbs
44
- env["app.breadcrumbs"] ||= Trail.new(env)
54
+ migajas_env["app.breadcrumbs"] ||= Trail.new(migajas_env)
45
55
  end
46
56
 
47
57
  # The Trail is just an `env`-aware Array, with some convenient sugar for
@@ -0,0 +1,50 @@
1
+ require "migajas"
2
+
3
+ module Migajas
4
+ # Provides a bridge for Migajas to work in Rails controllers, giving you the
5
+ # `breadcrumbs` method both in controllers and views.
6
+ #
7
+ # You can then add to it via action callbacks, like so:
8
+ #
9
+ # class ApplicationController
10
+ # before_action { breadcrumbs.add "Home", root_path }
11
+ # end
12
+ #
13
+ # class UsersController < ApplicationController
14
+ # before_action { breadcrumbs.add "Users", users_path }
15
+ # before_action(only: [:show, :edit, :update]) do
16
+ # breadcrumbs.add @user.name, @user
17
+ # end
18
+ # end
19
+ #
20
+ # You can also call `breadcrumbs.add` directly from your controller action:
21
+ #
22
+ # class UsersController < ApplicationController
23
+ # def edit_security
24
+ # breadcrumbs.add "Password", edit_security_user_path(@user)
25
+ # end
26
+ # end
27
+ #
28
+ # Then, from the view, you can just iterate over the `breadcrumbs` trail:
29
+ #
30
+ # <nav class="breadcrumbs" aria-label="Breadcrumb">
31
+ # <ol>
32
+ # <% breadcrumbs.each do |crumb| %>
33
+ # <li><%= link_to_unless crumb.current?, crumb.name, crumb.url %></li>
34
+ # <% end %>
35
+ # </ol>
36
+ # </nav>
37
+ #
38
+ module Rails
39
+ extend ActiveSupport::Concern
40
+ include Migajas
41
+
42
+ included do
43
+ helper_method :breadcrumbs
44
+ end
45
+
46
+ def migajas_env # :nodoc:
47
+ request.env
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Migajas
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migajas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Sanguinetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
@@ -31,16 +31,16 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
- description: Simple library to add breadcrumbs to your Cuba/Roda app
41
+ description: Simple library to add breadcrumbs to your Rack app
42
42
  email:
43
- - contacto@nicolassanguinetti.info
43
+ - foca@foca.io
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -48,6 +48,7 @@ files:
48
48
  - LICENSE
49
49
  - README.md
50
50
  - lib/migajas.rb
51
+ - lib/migajas/rails.rb
51
52
  - lib/migajas/version.rb
52
53
  homepage: http://github.com/foca/migajas
53
54
  licenses:
@@ -68,9 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
70
71
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.4.5.1
72
+ rubygems_version: 3.0.3
73
73
  signing_key:
74
74
  specification_version: 4
75
- summary: Breadcrumbs for your Cuba/Roda app
75
+ summary: Breadcrumbs for your Rack app
76
76
  test_files: []