panko 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d21ecbe2bf40f8bb5f6c8c1e414d771acc71224
4
+ data.tar.gz: 3dff0b7e16bdcc06a483f0d6b00f1647d209b450
5
+ SHA512:
6
+ metadata.gz: 8e56c3a7c0d58465b87ee3c3d4219e11f53fe26ad7f5a51bb878e0900e00f697a0beb55af85120d3a4381f46066ec0c5f62dafb970a92f22cf532f170eaca9b6
7
+ data.tar.gz: 9b85d360a731d21850820c23ee8085b0fbb801b0e2e9ca825f13a415d26154525b04d91a9faf62386483902d02a9aa36fbfb406d8bb64a584ef5ba63ea4fa11f
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in panko.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Barsoom AB
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Panko
2
+
3
+ Ruby breadcrumb trail generation the right way: object oriented outside the controller.
4
+
5
+ Super WiP!
6
+
7
+ ## TODO
8
+
9
+ * specs
10
+ * docs
11
+ * re-implement what we currently depend on breadcrumbs_on_rails for
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'panko'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install panko
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( http://github.com/<my-github-username>/panko/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
38
+
39
+ ## Thanks to
40
+
41
+ Thanks to Scott Burton for letting us [take over](http://www.scottburton.me/) the brilliant "Panko" gem name.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ module Panko
2
+ end
3
+
4
+ require "panko/version"
5
+ require "panko/base"
6
+ require "panko/crud"
@@ -0,0 +1,35 @@
1
+ require "attr_extras"
2
+ require "i18n"
3
+ require "active_support/all"
4
+
5
+ class Panko::Base
6
+ pattr_initialize :controller
7
+
8
+ def build
9
+ add_root
10
+ end
11
+
12
+ private
13
+
14
+ def add_root
15
+ add_breadcrumb t("layout.breadcrumb_root"), root_path
16
+ end
17
+
18
+ def t(*opts)
19
+ I18n.t(*opts)
20
+ end
21
+
22
+ # Delegate *_path to the controller.
23
+ def method_missing(name, *args)
24
+ if name.to_s.end_with?("_path")
25
+ controller.public_send(name, *args)
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ delegate :add_breadcrumb, :url_for,
34
+ to: :controller
35
+ end
@@ -0,0 +1,67 @@
1
+ require "panko/base"
2
+
3
+ class Panko::Crud < Panko::Base
4
+ pattr_initialize :controller, :persisted_record
5
+
6
+ def build
7
+ super
8
+ add_index
9
+ add_show
10
+ add_new_or_edit
11
+ end
12
+
13
+ private
14
+
15
+ def record_class
16
+ # E.g. "EmployeesBreadcrumbs" -> Employee.
17
+ self.class.name.sub(/Breadcrumbs$/, "").
18
+ singularize.constantize
19
+ end
20
+
21
+ def add_index
22
+ add_breadcrumb t("#{t_scope}.index.title"), index_path
23
+ end
24
+
25
+ def add_show
26
+ if persisted_record
27
+ add_breadcrumb persisted_record.to_s, show_path
28
+ end
29
+ end
30
+
31
+ def add_new_or_edit
32
+ if new?
33
+ add_breadcrumb t("#{t_scope}.new.title"), nil
34
+ elsif edit?
35
+ add_breadcrumb t("#{t_scope}.edit.title"), nil
36
+ end
37
+ end
38
+
39
+ def t_scope
40
+ # E.g. "employees".
41
+ record_class.name.tableize
42
+ end
43
+
44
+ def index_path
45
+ url_for(index_context)
46
+ end
47
+
48
+ def show_path
49
+ url_for(show_context)
50
+ end
51
+
52
+ def index_context
53
+ [ record_class ]
54
+ end
55
+
56
+ def show_context
57
+ [ persisted_record ]
58
+ end
59
+
60
+ def edit?
61
+ %w[edit update].include?(controller.action_name)
62
+ end
63
+
64
+ def new?
65
+ %w[new create].include?(controller.action_name)
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Panko
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'panko/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "panko"
8
+ spec.version = Panko::VERSION
9
+ spec.authors = ["Joakim Kolsjö", "Henrik Nyh"]
10
+ spec.email = ["all@barsoom.se"]
11
+ spec.summary = %q{Breadcrumb trails the right way: object-oriented outside the controller.}
12
+ spec.homepage = "https://github.com/barsoom/panko"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "attr_extras"
21
+ spec.add_dependency "breadcrumbs_on_rails"
22
+ spec.add_dependency "i18n"
23
+ spec.add_dependency "activesupport"
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+ require "panko/crud"
3
+
4
+ class Item
5
+ def to_s
6
+ "Item 123"
7
+ end
8
+ end
9
+
10
+ class ItemBreadcrumbs < Panko::Crud
11
+ end
12
+
13
+ describe Panko::Crud, "#build" do
14
+ let(:controller) { double(:controller, super_admin?: false, action_name: action_name, root_path: "/") }
15
+
16
+ context "in controller #index" do
17
+ let(:action_name) { "index" }
18
+
19
+ it "builds an index breadcrumb" do
20
+ expect_i18n "layout.breadcrumb_root" => "My root",
21
+ "items.index.title" => "Items"
22
+
23
+ expect_url_for [ Item ] => "/items"
24
+
25
+ expect_to_add_breadcrumb("My root", "/")
26
+ expect_to_add_breadcrumb("Items", "/items")
27
+
28
+ ItemBreadcrumbs.new(controller, nil).build
29
+ end
30
+ end
31
+
32
+ context "in controller #show" do
33
+ let(:action_name) { "show" }
34
+ let(:item) { Item.new }
35
+
36
+ it "builds a show breadcrumb" do
37
+ expect_i18n "layout.breadcrumb_root" => "My root",
38
+ "items.index.title" => "Items"
39
+
40
+ expect_url_for [ Item ] => "/items",
41
+ [ item ] => "/items/123"
42
+
43
+ expect_to_add_breadcrumb("My root", "/")
44
+ expect_to_add_breadcrumb("Items", "/items")
45
+ expect_to_add_breadcrumb("Item 123", "/items/123")
46
+
47
+ ItemBreadcrumbs.new(controller, item).build
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def expect_i18n(hash)
54
+ hash.each do |key, value|
55
+ expect(I18n).to receive(:t).with(key).and_return(value)
56
+ end
57
+ end
58
+
59
+ def expect_url_for(hash)
60
+ hash.each do |args, value|
61
+ expect(controller).to receive(:url_for).with(args).and_return(value)
62
+ end
63
+ end
64
+
65
+ def expect_to_add_breadcrumb(name, path)
66
+ expect(controller).to receive(:add_breadcrumb).with(name, path)
67
+ end
68
+ end
File without changes
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joakim Kolsjö
8
+ - Henrik Nyh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: attr_extras
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: breadcrumbs_on_rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: i18n
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: activesupport
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.5'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '1.5'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description:
113
+ email:
114
+ - all@barsoom.se
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/panko.rb
125
+ - lib/panko/base.rb
126
+ - lib/panko/crud.rb
127
+ - lib/panko/version.rb
128
+ - panko.gemspec
129
+ - spec/crud_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/barsoom/panko
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.0
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: 'Breadcrumb trails the right way: object-oriented outside the controller.'
155
+ test_files:
156
+ - spec/crud_spec.rb
157
+ - spec/spec_helper.rb