crumby 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails"
4
+
5
+ group :development do
6
+ gem 'rspec-rails'
7
+ gem "yard"
8
+ gem "bundler"
9
+ gem "jeweler"
10
+ gem "simplecov"
11
+ end
@@ -0,0 +1,115 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.6)
5
+ actionpack (= 3.2.6)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.6)
8
+ activemodel (= 3.2.6)
9
+ activesupport (= 3.2.6)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.1)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.6)
18
+ activesupport (= 3.2.6)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.6)
21
+ activemodel (= 3.2.6)
22
+ activesupport (= 3.2.6)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.6)
26
+ activemodel (= 3.2.6)
27
+ activesupport (= 3.2.6)
28
+ activesupport (3.2.6)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ diff-lcs (1.1.3)
34
+ erubis (2.7.0)
35
+ git (1.2.5)
36
+ hike (1.2.1)
37
+ i18n (0.6.0)
38
+ jeweler (1.8.4)
39
+ bundler (~> 1.0)
40
+ git (>= 1.2.5)
41
+ rake
42
+ rdoc
43
+ journey (1.0.4)
44
+ json (1.7.3)
45
+ mail (2.4.4)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.19)
50
+ multi_json (1.3.6)
51
+ polyglot (0.3.3)
52
+ rack (1.4.1)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.2.6)
60
+ actionmailer (= 3.2.6)
61
+ actionpack (= 3.2.6)
62
+ activerecord (= 3.2.6)
63
+ activeresource (= 3.2.6)
64
+ activesupport (= 3.2.6)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.6)
67
+ railties (3.2.6)
68
+ actionpack (= 3.2.6)
69
+ activesupport (= 3.2.6)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.11.0)
78
+ rspec-core (~> 2.11.0)
79
+ rspec-expectations (~> 2.11.0)
80
+ rspec-mocks (~> 2.11.0)
81
+ rspec-core (2.11.1)
82
+ rspec-expectations (2.11.1)
83
+ diff-lcs (~> 1.1.3)
84
+ rspec-mocks (2.11.1)
85
+ rspec-rails (2.11.0)
86
+ actionpack (>= 3.0)
87
+ activesupport (>= 3.0)
88
+ railties (>= 3.0)
89
+ rspec (~> 2.11.0)
90
+ simplecov (0.6.4)
91
+ multi_json (~> 1.0)
92
+ simplecov-html (~> 0.5.3)
93
+ simplecov-html (0.5.3)
94
+ sprockets (2.1.3)
95
+ hike (~> 1.2)
96
+ rack (~> 1.0)
97
+ tilt (~> 1.1, != 1.3.0)
98
+ thor (0.15.4)
99
+ tilt (1.3.3)
100
+ treetop (1.4.10)
101
+ polyglot
102
+ polyglot (>= 0.3.1)
103
+ tzinfo (0.3.33)
104
+ yard (0.8.2.1)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ bundler
111
+ jeweler
112
+ rails
113
+ rspec-rails
114
+ simplecov
115
+ yard
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Christoph Chilian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ = Crumby
2
+ A simple breadcrumb plugin for rails
3
+
4
+ == Installation
5
+ add to Gemfile
6
+ gem 'crumby'
7
+
8
+ == Configuration
9
+
10
+ Crumby.configure do
11
+ # configure the default renderer
12
+ # renderer = Renderer::Haml
13
+ end
14
+
15
+ == Requirements
16
+
17
+ * Rails 3 (http://github.com/rails/rails)
18
+
19
+ == Example
20
+
21
+ === controller
22
+ you can add entries global by before_filter and in each methods/actions
23
+
24
+ class Addmin::BookController < ApplicationController
25
+ before_filter { add_crumby "Dashboard", :root }
26
+ before_filter { add_crumby "Admin", :admin_root }
27
+ def index
28
+ add_crumby [:admin, :books]
29
+ end
30
+ def show
31
+ add_crumby [:admin, @book]
32
+ end
33
+ end
34
+
35
+ === layout
36
+ %html
37
+ %head
38
+ %title= crumby_title "The Admin App"
39
+ %body
40
+ #breadcrumb= crumby
41
+
42
+ === add_crumby
43
+ add a new entry into breadcrumb trail
44
+
45
+ add_crumby :books
46
+ add_crumby @book
47
+ add_crumby [:admin, @book]
48
+ add_crumby "Books", :admin_books
49
+ add_crumby "Books", [:admin,:books]
50
+ add_crumby "Book", [:admin, @book]
51
+ add_crumby "Google", "http://google.de"
52
+
53
+ === scopes
54
+ You can use scopes to have more than one breadcrumb
55
+ :subcrumy is equal to "subcrumb"
56
+
57
+ add_crumby :books, scope: :subcrumb
58
+ add_crumby :books, scope: "subcrumb"
59
+ crumby :subcrumb
60
+ crumby "subcrumb"
61
+
62
+ == History
63
+
64
+ * 0.1 first release
65
+
66
+ == Roadmap
67
+
68
+ * Complete all specs
69
+
70
+ == Maintainers
71
+
72
+ * Team Phatworx (http://github.com/phatworx)
73
+ * Marco Scholl (http://github.com/traxanos)
74
+
75
+ == Contributing to Crumby
76
+
77
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
78
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
79
+ * Fork the project
80
+ * Start a feature/bugfix branch
81
+ * Commit and push until you are happy with your contribution
82
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
83
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
84
+
85
+ == Copyright
86
+
87
+ Copyright (c) 2012 Marco Scholl. See LICENSE.txt for further details.
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
9
+ gem.name = "crumby"
10
+ gem.homepage = "http://github.com/phatworx/crumby"
11
+ gem.license = "MIT"
12
+ gem.summary = %Q{A simple breadcrumb plugin for rails}
13
+ gem.description = %Q{A simple breadcrumb plugin for rails}
14
+ gem.email = "develop@marco-scholl.de"
15
+ gem.authors = ["Marco Scholl"]
16
+ gem.files.exclude 'spec'
17
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
18
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
19
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
20
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
21
+ end
22
+ Jeweler::RubygemsDotOrgTasks.new
23
+
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+
27
+ RSpec::Core::RakeTask.new(:spec) do |spec|
28
+ spec.pattern = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ desc "Run tests with SimpleCov"
32
+ RSpec::Core::RakeTask.new('coverage') do |t|
33
+ ENV['COVERAGE'] = "true"
34
+ end
35
+
36
+ task :default => :spec
37
+
38
+ require 'yard'
39
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "crumby"
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marco Scholl"]
12
+ s.date = "2012-07-31"
13
+ s.description = "A simple breadcrumb plugin for rails"
14
+ s.email = "develop@marco-scholl.de"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "crumby.gemspec",
29
+ "lib/crumby.rb",
30
+ "lib/crumby/entry.rb",
31
+ "lib/crumby/helper.rb",
32
+ "lib/crumby/helper/controller.rb",
33
+ "lib/crumby/helper/view.rb",
34
+ "lib/crumby/renderer.rb",
35
+ "lib/crumby/renderer/base.rb",
36
+ "lib/crumby/renderer/haml.rb",
37
+ "lib/crumby/trail.rb",
38
+ "spec/crumby/entry_spec.rb",
39
+ "spec/crumby/helper_spec.rb",
40
+ "spec/crumby/renderer/base_spec.rb",
41
+ "spec/crumby/trail_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+ s.homepage = "http://github.com/phatworx/crumby"
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = "1.8.24"
48
+ s.summary = "A simple breadcrumb plugin for rails"
49
+
50
+ if s.respond_to? :specification_version then
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
55
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
56
+ s.add_development_dependency(%q<yard>, [">= 0"])
57
+ s.add_development_dependency(%q<bundler>, [">= 0"])
58
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
59
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<rails>, [">= 0"])
62
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
63
+ s.add_dependency(%q<yard>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, [">= 0"])
65
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
+ s.add_dependency(%q<simplecov>, [">= 0"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<rails>, [">= 0"])
70
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
71
+ s.add_dependency(%q<yard>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
+ s.add_dependency(%q<simplecov>, [">= 0"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,41 @@
1
+ require 'active_support/lazy_load_hooks'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+
4
+ # crumy is a breadcrumb plugin for rails
5
+ module Crumby
6
+ autoload :Entry, 'crumby/entry'
7
+ autoload :Trail, 'crumby/trail'
8
+ autoload :Helper, 'crumby/helper'
9
+ autoload :Renderer, 'crumby/renderer'
10
+
11
+ mattr_accessor :renderer
12
+ # configure the default renderer
13
+ @@renderer = Renderer::Haml
14
+
15
+ class << self
16
+ # configure crumby
17
+ # @example
18
+ # Crumby.configure do
19
+ # # configure the default renderer
20
+ # # renderer = Renderer::Haml
21
+ # end
22
+ def configure(&block)
23
+ self.instance_eval &block
24
+ end
25
+
26
+ # initialize the crumby plugin.
27
+ # includes Controller and View helpers
28
+ def init!
29
+ ActiveSupport.on_load(:action_controller) do
30
+ ActionController::Base.send :include, Crumby::Helper::ControllerHelper
31
+ end
32
+
33
+ ActiveSupport.on_load(:action_view) do
34
+ ActionView::Base.send :include, Crumby::Helper::ViewHelper
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ Crumby.init!
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ module Crumby
3
+
4
+ # represent an entry of a breadcrumb menu
5
+ class Entry < Struct.new(:trail, :position, :label, :route, :options)
6
+
7
+ # Returns total entries
8
+ # @return [Fixnum]
9
+ def total
10
+ trail.count
11
+ end
12
+
13
+ # Returns if first entry
14
+ # @return [Boolean]
15
+ def first?
16
+ position.zero?
17
+ end
18
+
19
+ # Returns if last entry
20
+ # @return [Boolean]
21
+ def last?
22
+ (total - position - 1).zero?
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ # helper package
3
+ module Crumby::Helper
4
+ autoload :ViewHelper, 'crumby/helper/view'
5
+ autoload :ControllerHelper, 'crumby/helper/controller'
6
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ module Crumby::Helper
3
+ # controller helper
4
+ module ControllerHelper
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ helper_method :crumby_title
9
+ helper_method :crumby_trail
10
+ end
11
+
12
+ # return crumby_trail by scope
13
+ # @param [Symbol, String] scope
14
+ def crumby_trail(scope = :default)
15
+ raise ArgumentError if scope.nil?
16
+ scope = scope.to_sym
17
+ @crumby_trails = {} if @crumby_trails.nil?
18
+ @crumby_trails[scope] ||= Crumby::Trail.new
19
+ end
20
+
21
+ # render trail
22
+ # @see Crumby::Trail#render
23
+ # @see Crumby::Renderer::Base
24
+ # @overload crumby(options)
25
+ # @param [Hash] options passthrough to Trail#render
26
+ # @option options [String, Symbol] :scope extract scope from options before passthrough
27
+ # @overload crumby(scope, options)
28
+ # @param [Symbol, String] scope scope of trail
29
+ # @param [Hash] options passthrough to Trail#render
30
+ # @option options [String, Symbol] :scope extract scope from options before passthrough
31
+ def add_crumby(*args)
32
+ options = args.extract_options!
33
+ scope = options.delete(:scope) || :default
34
+ crumby_trail(scope).add(*args, options)
35
+ end
36
+
37
+
38
+ # render trail
39
+ # @see Crumby::Trail#title
40
+ # @overload crumby(options)
41
+ # @param [Hash] options passthrough to Crumby::Trail#title
42
+ # @option options [String, Symbol] :scope extract scope from options before passthrough
43
+ # @overload crumby(suffix, options)
44
+ # @param [String] suffix passthrough to Crumby::Trail#title
45
+ # @param [Hash] options passthrough to Crumby::Trail#title
46
+ # @option options [String, Symbol] :scope extract scope from options before passthrough
47
+ def crumby_title(*args)
48
+ options = args.extract_options!
49
+ scope = options.delete(:scope) || :default
50
+ crumby_trail(scope).title(*args, options)
51
+ end
52
+ end
53
+ end