migajas 0.9.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 +7 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/lib/migajas.rb +82 -0
- data/lib/migajas/version.rb +3 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2224e900cfa8368a0da6bcd4d8b9fed287645e40
|
4
|
+
data.tar.gz: 219915ed490c9a9d5d4f7336e91ced8735b366f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e00e0bb52756db949d5a02827e466e32e600aaf2164d30eea9be9094c7e145b67937d5bb074f19be4959b97c7a722b66ef9e3cc11e66cbb26a079ff717c6454
|
7
|
+
data.tar.gz: 39489dd99c8ce61f52c0eba3af37a715f8c64930b5c414546bf33809617e19024d755dc5777865713c59a4c3a03d1a20ea959a19be2118c1ef3cb55969527fc6
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Nicolas Sanguinetti <hi@nicolassanguinetti.info>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Migajas
|
2
|
+
|
3
|
+
Migajas is a tiny library for adding breadcrumbs to a routing tree framework,
|
4
|
+
like Cuba or Roda.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
First, build up your trail of crumbs as you match your routes:
|
9
|
+
|
10
|
+
``` ruby
|
11
|
+
Cuba.plugin Migajas
|
12
|
+
|
13
|
+
Cuba.define do
|
14
|
+
breacrumbs << "Home"
|
15
|
+
|
16
|
+
on "users" do
|
17
|
+
breadcrumbs << "Users"
|
18
|
+
|
19
|
+
on get do
|
20
|
+
# render the list of users
|
21
|
+
end
|
22
|
+
|
23
|
+
on ":id" do |id|
|
24
|
+
user = User[id]
|
25
|
+
breadcrumbs << user.name
|
26
|
+
|
27
|
+
on get do
|
28
|
+
# render the user profile page
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Then, in the view, go over the `breadcrumbs` list:
|
36
|
+
|
37
|
+
``` erb
|
38
|
+
<ol class="breadcrumbs">
|
39
|
+
<% breadcrumbs.each do |crumb| %>
|
40
|
+
<li class="<%= "active" if crumb.current? %>">
|
41
|
+
<a href="<%= crumb.url %>"><%= crumb.name %></a>
|
42
|
+
</li>
|
43
|
+
<% end %>
|
44
|
+
</ol>
|
45
|
+
```
|
46
|
+
|
47
|
+
That's it :)
|
48
|
+
|
49
|
+
## Install
|
50
|
+
|
51
|
+
gem install migajas
|
52
|
+
|
53
|
+
## What's in a name?
|
54
|
+
|
55
|
+
`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.)
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
This project is shared under the MIT license. See the attached [LICENSE][] file
|
61
|
+
for details.
|
62
|
+
|
63
|
+
[LICENSE]: ./LICENSE
|
data/lib/migajas.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Migajas
|
2
|
+
# Public: List of breadcrumbs encountered in this request. Add to this list
|
3
|
+
# any breadcrumb as you go through your routing tree in the app:
|
4
|
+
#
|
5
|
+
# Example
|
6
|
+
#
|
7
|
+
# define do
|
8
|
+
# breadcrumbs << "Home"
|
9
|
+
#
|
10
|
+
# on "users" do
|
11
|
+
# breadcrumbs << "Users"
|
12
|
+
#
|
13
|
+
# on get do
|
14
|
+
# # render the list
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# on ":id" do |id|
|
18
|
+
# user = User[id]
|
19
|
+
# breadcrumbs << user.name
|
20
|
+
#
|
21
|
+
# # etc
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# This will automatically build a list with the following breadcrumbs:
|
27
|
+
#
|
28
|
+
# [
|
29
|
+
# Migajas::Crumb.new("Home", "/"),
|
30
|
+
# Migajas::Crumb.new("Users", "/users"),
|
31
|
+
# Migajas::Crumb.new("Profile", "/users/5")
|
32
|
+
# ]
|
33
|
+
#
|
34
|
+
# In the view you can, then:
|
35
|
+
#
|
36
|
+
# <% breadcrumbs.each do |crumb| %>
|
37
|
+
# <li class="<%= "active" if crumb.current? %>">
|
38
|
+
# <a href="<%= crumb.url %>"><%= crumb.name %></a>
|
39
|
+
# </li>
|
40
|
+
# <% end %>
|
41
|
+
#
|
42
|
+
# Returns a Migajas::Trail.
|
43
|
+
def breadcrumbs
|
44
|
+
env["app.breadcrumbs"] ||= Trail.new(env)
|
45
|
+
end
|
46
|
+
|
47
|
+
# The Trail is just an `env`-aware Array, with some convenient sugar for
|
48
|
+
# adding items to it.
|
49
|
+
class Trail < Array
|
50
|
+
def initialize(env)
|
51
|
+
@env = env
|
52
|
+
super()
|
53
|
+
end
|
54
|
+
|
55
|
+
# Add a new crumb to this trail. This takes care of calculating the URL
|
56
|
+
# from the path currently matched by Cuba, so all you need to provide is
|
57
|
+
# the name.
|
58
|
+
#
|
59
|
+
# Returns self.
|
60
|
+
def add(name, url = @env["SCRIPT_NAME"])
|
61
|
+
push Crumb.new(name, url, @env)
|
62
|
+
end
|
63
|
+
alias_method :<<, :add
|
64
|
+
|
65
|
+
# Crumbs are dumb values that know their #name, their #url, and whether
|
66
|
+
# they match the current URL (according to the `env`, which they inherit
|
67
|
+
# from their trail).
|
68
|
+
class Crumb
|
69
|
+
attr_reader :name, :url
|
70
|
+
|
71
|
+
def initialize(name, url, env)
|
72
|
+
@name = name
|
73
|
+
@url = url
|
74
|
+
@env = env
|
75
|
+
end
|
76
|
+
|
77
|
+
def current?
|
78
|
+
url == (@env["SCRIPT_NAME"] + @env["PATH_INFO"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: migajas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Sanguinetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cutest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cuba
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: Simple library to add breadcrumbs to your Cuba/Roda app
|
42
|
+
email:
|
43
|
+
- contacto@nicolassanguinetti.info
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- lib/migajas.rb
|
51
|
+
- lib/migajas/version.rb
|
52
|
+
homepage: http://github.com/foca/migajas
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.4.5.1
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Breadcrumbs for your Cuba/Roda app
|
76
|
+
test_files: []
|