breadcrumbs_for 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/README.rdoc CHANGED
@@ -1,12 +1,16 @@
1
1
  = breadcrumbs_for
2
2
 
3
- Breadcrumbs for Rails made right.
3
+ Breadcrumbs Rails helper.
4
+
5
+ Breadcrumbs helper for Rails done in a rails way.
6
+
7
+ Built on url_for, your routes, model names and i18n.
4
8
 
5
9
  == Installation
6
10
  gem install breadcrumbs_for
7
11
 
8
12
  == Requirements
9
- Was tested with Rails 3.0.0
13
+ Was tested with Rails 3
10
14
 
11
15
  == Usage
12
16
  Let say:
@@ -32,7 +36,6 @@ etc.
32
36
  Note: There is a shorter alias crumbs_for, so you can do:
33
37
  crumbs_for :blogs, @blog
34
38
 
35
-
36
39
  You can even do the following:
37
40
  breadcrumbs_for {:controller=>'blogs', :action=>'index', :crumb=>'All Blogs'}, @blog
38
41
  Note on :crumb=>'All Blogs'. Here you need to provide the breadcrumb caption text directly via the :crumb key.
@@ -40,6 +43,43 @@ Note on :crumb=>'All Blogs'. Here you need to provide the breadcrumb caption tex
40
43
  If you have an admin_path in your routes you can do:
41
44
  breadcrumbs_for :admin, [:admin,:blogs], ['new', :admin, @blog], :crumbs_options=>{:root=>false}
42
45
 
46
+ === Produced HTML
47
+ By default it will render breadcrumbs as an unordered list.
48
+
49
+ The following code
50
+
51
+ <%= crumbs_for :posts, 'New' %>
52
+
53
+ will produce html:
54
+
55
+ <ul class="breadcrumbs">
56
+ <li class="crumb root">
57
+ <a href="/" class="crumb home_crumb">Home</a>
58
+ </li>
59
+ <li class="sep">/</li>
60
+ <li class="crumb ">
61
+ <a href="/posts" class="crumb">Posts</a>
62
+ </li>
63
+ <li class="sep">/</li>
64
+ <li class="crumb active">
65
+ New
66
+ </li>
67
+ </ul>
68
+
69
+ You can also render bredcrumbs in plain.
70
+
71
+ The following code
72
+
73
+ <%= crumbs_for :posts, 'New', :crumbs_options => { :type => :plain } %>
74
+
75
+ will produce html:
76
+
77
+ <a href="/" class="crumb home_crumb">Home</a>
78
+ <span class="sep">/</span>
79
+ <a href="/admin/themes" class="crumb">Themes</a>
80
+ <span class="sep">/</span>
81
+ New
82
+
43
83
  === Customize
44
84
  * Don't inculde the Home(root) link:
45
85
  breadcrumbs_for :blogs, @blog, :crumbs_options=>{:root=>false}
@@ -61,17 +101,23 @@ Define captions for breadcrumbs in your locale file:
61
101
  blogs: 'The blogs'
62
102
  posts: 'The posts'
63
103
 
104
+ === Tips & Tricks
105
+ When providing action as a String it will include action name in breadcrumb caption.
106
+
107
+ crumbs_for :blogs, ['edit', @blog] # => Home / Blogs / Edit My blog
108
+
109
+ When providing action as a Symbol it will skip action name in breadcrumb caption.
110
+
111
+ crumbs_for :blogs, [:edit, @blog] # => Home / Blogs / My blog
112
+
64
113
  == Note on Patches/Pull Requests
65
114
 
66
- ((*Patches/Pull Requests are welcome!*))
115
+ Patches/Pull Requests are welcome!
67
116
 
68
117
  * Fork the project.
69
118
  * Make your feature addition or bug fix.
70
- * Add tests for it. This is important so I don't break it in a
71
- future version unintentionally.
72
- * Commit, do not mess with rakefile, version, or history.
73
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
74
- * Send me a pull request. Bonus points for topic branches.
119
+ * Commit.
120
+ * Send a pull request.
75
121
 
76
122
  == Copyright
77
123
 
data/Rakefile CHANGED
@@ -5,12 +5,11 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "breadcrumbs_for"
8
- gem.summary = %Q{Breadcrumbs for Rails made right.}
9
- gem.description = %Q{Breadcrumbs for Rails done in a rails way. Built on url_for, your routes and i18n.}
8
+ gem.summary = %Q{Breadcrumbs Rails helper.}
9
+ gem.description = %Q{Breadcrumbs helper for Rails done in a rails way. Built on url_for, your routes, model names and i18n.}
10
10
  gem.email = "naumovmail@gmail.com"
11
11
  gem.homepage = "http://github.com/naumov/breadcrumbs_for"
12
12
  gem.authors = ["Dmitry Naumov"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
13
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
14
  end
16
15
  Jeweler::GemcutterTasks.new
@@ -18,26 +17,6 @@ rescue LoadError
18
17
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
18
  end
20
19
 
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
20
  task :test => :check_dependencies
42
21
 
43
22
  task :default => :test
@@ -50,4 +29,4 @@ Rake::RDocTask.new do |rdoc|
50
29
  rdoc.title = "breadcrumbs_for #{version}"
51
30
  rdoc.rdoc_files.include('README*')
52
31
  rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
32
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,53 +1,45 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{breadcrumbs_for}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dmitry Naumov"]
12
- s.date = %q{2010-10-30}
13
- s.description = %q{Breadcrumbs for Rails done in a rails way. Built on url_for, your routes and i18n.}
12
+ s.date = %q{2010-11-19}
13
+ s.description = %q{Breadcrumbs helper for Rails done in a rails way. Built on url_for, your routes, model names and i18n.}
14
14
  s.email = %q{naumovmail@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "breadcrumbs_for.gemspec",
26
- "init.rb",
27
- "lib/breadcrumbs_for.rb",
28
- "test/helper.rb",
29
- "test/test_breadcrumbs_for.rb"
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "breadcrumbs_for.gemspec",
27
+ "init.rb",
28
+ "lib/breadcrumbs_for.rb"
30
29
  ]
31
30
  s.homepage = %q{http://github.com/naumov/breadcrumbs_for}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.7}
34
- s.summary = %q{Breadcrumbs for Rails made right.}
35
- s.test_files = [
36
- "test/helper.rb",
37
- "test/test_breadcrumbs_for.rb"
38
- ]
33
+ s.rubygems_version = %q{1.3.6}
34
+ s.summary = %q{Breadcrumbs Rails helper.}
39
35
 
40
36
  if s.respond_to? :specification_version then
41
37
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
38
  s.specification_version = 3
43
39
 
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
41
  else
47
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
42
  end
49
43
  else
50
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
44
  end
52
45
  end
53
-
@@ -7,7 +7,7 @@ module BreadcrumbsFor
7
7
  list.each_with_index do |crumb,index|
8
8
  caption = crumb_to_caption(crumb)
9
9
  is_last_crumb = ((index+1) == crumbs_count)
10
- item = is_last_crumb ? caption : crumb_link(caption, url_for(crumb))
10
+ item = crumb.is_a?(String) ? caption : crumb_link(caption, url_for(crumb))
11
11
  crumbs << crumb_html(item,options,is_last_crumb ? 'active' : nil)
12
12
  end
13
13
  crumbs_html(crumbs,options)
@@ -73,14 +73,14 @@ module BreadcrumbsFor
73
73
  if crumb.size>1
74
74
  case crumb.first.class.to_s
75
75
  when 'Symbol' # Is a namespace. Skip it
76
- cramb_caption(crumb.last)
76
+ crumb_to_caption(crumb.last)
77
77
  when 'String' # Is an action name. Use it
78
78
  string_to_caption(crumb.first) << ' ' << cramb_caption(crumb.last)
79
79
  else # Use last item only
80
- cramb_caption(crumb.last)
80
+ cramb_to_caption(crumb.last)
81
81
  end
82
82
  else
83
- cramb_caption(crumb[0])
83
+ cramb_to_caption(crumb[0])
84
84
  end
85
85
  end
86
86
 
@@ -99,14 +99,16 @@ module BreadcrumbsFor
99
99
  end
100
100
  end
101
101
 
102
- def cramb_caption crumb
103
- if crumb.respond_to?(:title)
104
- crumb.title
105
- elsif crumb.respond_to?(:name)
106
- crumb.name
107
- else
108
- crumb.class.to_s.humanize
102
+ def cramb_caption obj, method='name'
103
+ [method,'name','title'].each do |name_method|
104
+ if obj.respond_to?(name_method)
105
+ was_method = "#{name_method}_was"
106
+ changed_method = "#{name_method}_changed?"
107
+ tracking_enabled = obj.respond_to?(was_method) && obj.respond_to?(changed_method)
108
+ return (tracking_enabled && obj.send(changed_method)) ? obj.send(was_method) : obj.send(method.to_s)
109
+ end
109
110
  end
111
+ crumb.class.to_s.humanize
110
112
  end
111
113
  end
112
114
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadcrumbs_for
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Dmitry Naumov
@@ -15,24 +14,11 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-30 00:00:00 +03:00
17
+ date: 2010-11-19 00:00:00 +01:00
19
18
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: thoughtbot-shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
35
- description: Breadcrumbs for Rails done in a rails way. Built on url_for, your routes and i18n.
19
+ dependencies: []
20
+
21
+ description: Breadcrumbs helper for Rails done in a rails way. Built on url_for, your routes, model names and i18n.
36
22
  email: naumovmail@gmail.com
37
23
  executables: []
38
24
 
@@ -43,6 +29,7 @@ extra_rdoc_files:
43
29
  - README.rdoc
44
30
  files:
45
31
  - .document
32
+ - .gitignore
46
33
  - LICENSE
47
34
  - README.rdoc
48
35
  - Rakefile
@@ -50,42 +37,35 @@ files:
50
37
  - breadcrumbs_for.gemspec
51
38
  - init.rb
52
39
  - lib/breadcrumbs_for.rb
53
- - test/helper.rb
54
- - test/test_breadcrumbs_for.rb
55
40
  has_rdoc: true
56
41
  homepage: http://github.com/naumov/breadcrumbs_for
57
42
  licenses: []
58
43
 
59
44
  post_install_message:
60
- rdoc_options: []
61
-
45
+ rdoc_options:
46
+ - --charset=UTF-8
62
47
  require_paths:
63
48
  - lib
64
49
  required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
50
  requirements:
67
51
  - - ">="
68
52
  - !ruby/object:Gem::Version
69
- hash: 3
70
53
  segments:
71
54
  - 0
72
55
  version: "0"
73
56
  required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
57
  requirements:
76
58
  - - ">="
77
59
  - !ruby/object:Gem::Version
78
- hash: 3
79
60
  segments:
80
61
  - 0
81
62
  version: "0"
82
63
  requirements: []
83
64
 
84
65
  rubyforge_project:
85
- rubygems_version: 1.3.7
66
+ rubygems_version: 1.3.6
86
67
  signing_key:
87
68
  specification_version: 3
88
- summary: Breadcrumbs for Rails made right.
89
- test_files:
90
- - test/helper.rb
91
- - test/test_breadcrumbs_for.rb
69
+ summary: Breadcrumbs Rails helper.
70
+ test_files: []
71
+
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'breadcrumbs_for'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestBreadcrumbsFor < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end