gretel-lite 3.0.10

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.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.travis.yml +16 -0
  4. data/CHANGELOG.md +56 -0
  5. data/Gemfile +23 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +376 -0
  8. data/Rakefile +10 -0
  9. data/gemfiles/Gemfile-rails.3.1.x +19 -0
  10. data/gemfiles/Gemfile-rails.3.2.x +19 -0
  11. data/gemfiles/Gemfile-rails.4.0.x +19 -0
  12. data/gemfiles/Gemfile-rails.4.1.x +19 -0
  13. data/gretel.gemspec +23 -0
  14. data/lib/generators/gretel/USAGE +8 -0
  15. data/lib/generators/gretel/install_generator.rb +12 -0
  16. data/lib/generators/gretel/templates/breadcrumbs.rb +28 -0
  17. data/lib/gretel.rb +82 -0
  18. data/lib/gretel/crumb.rb +68 -0
  19. data/lib/gretel/crumbs.rb +64 -0
  20. data/lib/gretel/deprecated.rb +1 -0
  21. data/lib/gretel/deprecated/default_style_key.rb +25 -0
  22. data/lib/gretel/deprecated/layout.rb +15 -0
  23. data/lib/gretel/deprecated/show_root_alone.rb +27 -0
  24. data/lib/gretel/deprecated/yield_links.rb +44 -0
  25. data/lib/gretel/link.rb +39 -0
  26. data/lib/gretel/renderer.rb +254 -0
  27. data/lib/gretel/resettable.rb +13 -0
  28. data/lib/gretel/version.rb +3 -0
  29. data/lib/gretel/view_helpers.rb +71 -0
  30. data/test/deprecated_test.rb +45 -0
  31. data/test/dummy/Rakefile +7 -0
  32. data/test/dummy/app/assets/javascripts/application.js +15 -0
  33. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  34. data/test/dummy/app/controllers/application_controller.rb +3 -0
  35. data/test/dummy/app/helpers/application_helper.rb +5 -0
  36. data/test/dummy/app/mailers/.gitkeep +0 -0
  37. data/test/dummy/app/models/.gitkeep +0 -0
  38. data/test/dummy/app/models/issue.rb +3 -0
  39. data/test/dummy/app/models/project.rb +3 -0
  40. data/test/dummy/app/views/breadcrumbs/site.rb +3 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/config/application.rb +14 -0
  43. data/test/dummy/config/boot.rb +10 -0
  44. data/test/dummy/config/breadcrumbs.rb +3 -0
  45. data/test/dummy/config/breadcrumbs/test_crumbs.rb +85 -0
  46. data/test/dummy/config/database.yml +25 -0
  47. data/test/dummy/config/environment.rb +5 -0
  48. data/test/dummy/config/environments/development.rb +2 -0
  49. data/test/dummy/config/environments/production.rb +2 -0
  50. data/test/dummy/config/environments/test.rb +2 -0
  51. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/dummy/config/initializers/inflections.rb +15 -0
  53. data/test/dummy/config/initializers/mime_types.rb +5 -0
  54. data/test/dummy/config/initializers/secret_token.rb +7 -0
  55. data/test/dummy/config/initializers/session_store.rb +8 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +5 -0
  58. data/test/dummy/config/routes.rb +11 -0
  59. data/test/dummy/db/migrate/20130122163007_create_projects.rb +9 -0
  60. data/test/dummy/db/migrate/20130122163051_create_issues.rb +10 -0
  61. data/test/dummy/db/schema.rb +29 -0
  62. data/test/dummy/lib/assets/.gitkeep +0 -0
  63. data/test/dummy/log/.gitkeep +0 -0
  64. data/test/dummy/public/404.html +26 -0
  65. data/test/dummy/public/422.html +26 -0
  66. data/test/dummy/public/500.html +25 -0
  67. data/test/dummy/public/favicon.ico +0 -0
  68. data/test/dummy/script/rails +6 -0
  69. data/test/fixtures/issues.yml +4 -0
  70. data/test/fixtures/projects.yml +3 -0
  71. data/test/gretel_test.rb +24 -0
  72. data/test/helper_methods_test.rb +546 -0
  73. data/test/test_helper.rb +15 -0
  74. metadata +205 -0
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "gretel", :path => ".."
4
+
5
+ gem "rails", "~> 3.1.0"
6
+ gem "sqlite3"
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+
19
+ gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "gretel", :path => ".."
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "sqlite3"
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+
19
+ gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "gretel", :path => ".."
4
+
5
+ gem "rails", "~> 4.0.0"
6
+ gem "sqlite3"
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+
19
+ gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "gretel", :path => ".."
4
+
5
+ gem "rails", "~> 4.1.0"
6
+ gem "sqlite3"
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+
19
+ gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
data/gretel.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gretel/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gretel-lite"
8
+ gem.version = Gretel::VERSION
9
+ gem.authors = ["Lasse Bunk", "Aleksander Sumowski"]
10
+ gem.email = ["lassebunk@gmail.com", "j@sumowski.pl"]
11
+ gem.description = %q{Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.}
12
+ gem.summary = %q{Flexible Ruby on Rails breadcrumbs plugin.}
13
+ gem.homepage = "http://github.com/aleksandersumowski/gretel"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.test_files = gem.files.grep(%r{^test/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "activesupport", ">= 3.1.0"
21
+ gem.add_dependency "railties", ">= 3.1.0"
22
+ gem.add_development_dependency "sqlite3"
23
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a sample breadcrumbs configuration file for Gretel.
3
+
4
+ Example:
5
+ rails generate gretel:install
6
+
7
+ This will create:
8
+ config/breadcrumbs.rb
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+
3
+ module Gretel
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc "Creates a sample configuration file in config/breadcrumbs.rb"
8
+ def create_config_file
9
+ copy_file "breadcrumbs.rb", "config/breadcrumbs.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ crumb :root do
2
+ link "Home", root_path
3
+ end
4
+
5
+ # crumb :projects do
6
+ # link "Projects", projects_path
7
+ # end
8
+
9
+ # crumb :project do |project|
10
+ # link project.name, project_path(project)
11
+ # parent :projects
12
+ # end
13
+
14
+ # crumb :project_issues do |project|
15
+ # link "Issues", project_issues_path(project)
16
+ # parent :project, project
17
+ # end
18
+
19
+ # crumb :issue do |issue|
20
+ # link issue.title, issue_path(issue)
21
+ # parent :project_issues, issue.project
22
+ # end
23
+
24
+ # If you want to split your breadcrumbs configuration over multiple files, you
25
+ # can create a folder named `config/breadcrumbs` and put your configuration
26
+ # files there. All *.rb files (e.g. `frontend.rb` or `products.rb`) in that
27
+ # folder are loaded and reloaded automatically when you change them, just like
28
+ # this file (`config/breadcrumbs.rb`).
data/lib/gretel.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'gretel/version'
2
+ require 'gretel/resettable'
3
+ require 'gretel/crumbs'
4
+ require 'gretel/crumb'
5
+ require 'gretel/link'
6
+ require 'gretel/renderer'
7
+ require 'gretel/view_helpers'
8
+ require 'gretel/deprecated'
9
+
10
+ module Gretel
11
+ class << self
12
+ include Resettable
13
+
14
+ # Returns the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+
15
+ # in the app and all loaded engines. Breadcrumbs set in the app will override
16
+ # breadcrumbs set in engines.
17
+ def breadcrumb_paths
18
+ @breadcrumb_paths ||= begin
19
+ engines = Rails::Engine::Railties.respond_to?(:engines) ?
20
+ Rails::Engine::Railties.engines :
21
+ Rails::Engine.subclasses.map(&:instance)
22
+
23
+ engine_roots = engines.map { |e| e.config.root }
24
+
25
+ [*engine_roots, Rails.root].map do |root|
26
+ [root.join("config", "breadcrumbs.rb"),
27
+ root.join("config", "breadcrumbs", "**", "*.rb"),
28
+ root.join("app", "views", "breadcrumbs", "**", "*.rb")]
29
+ end.flatten
30
+ end
31
+ end
32
+
33
+ # Sets the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+.
34
+ def breadcrumb_paths=(paths)
35
+ @breadcrumb_paths = paths
36
+ end
37
+
38
+ # Whether to suppress deprecation warnings.
39
+ def suppress_deprecation_warnings?
40
+ !!@suppress_deprecation_warnings
41
+ end
42
+
43
+ # Sets whether to suppress deprecation warnings.
44
+ def suppress_deprecation_warnings=(value)
45
+ @suppress_deprecation_warnings = value
46
+ end
47
+
48
+ # Shows a deprecation warning.
49
+ def show_deprecation_warning(message)
50
+ return if suppress_deprecation_warnings?
51
+ message = "[Gretel] #{message}"
52
+ puts message
53
+ Rails.logger.warn message
54
+ end
55
+
56
+ # Array of Rails environment names with automatic configuration reload. Default is +["development"]+.
57
+ def reload_environments
58
+ @reload_environments ||= ["development"]
59
+ end
60
+
61
+ # Registers a style for later use.
62
+ #
63
+ # Gretel.register_style :ul, { container_tag: :ul, fragment_tag: :li }
64
+ def register_style(style, options)
65
+ Gretel::Renderer.register_style style, options
66
+ end
67
+
68
+ # Sets the Rails environment names with automatic configuration reload. Default is +["development"]+.
69
+ attr_writer :reload_environments
70
+
71
+ # Yields this +Gretel+ to be configured.
72
+ #
73
+ # Gretel.configure do |config|
74
+ # config.reload_environments << "staging"
75
+ # end
76
+ def configure
77
+ yield self
78
+ end
79
+ end
80
+ end
81
+
82
+ ActionView::Base.send :include, Gretel::ViewHelpers
@@ -0,0 +1,68 @@
1
+ module Gretel
2
+ class Crumb
3
+ # Initializes a new crumb from the given +key+.
4
+ # It finds the breadcrumb created in +Gretel::Crumbs.layout+ and renders the block using the arguments supplied in +args+.
5
+ def initialize(context, key, *args)
6
+ if key.class.respond_to?(:model_name)
7
+ # Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
8
+ args.unshift key
9
+ key = key.class.model_name.to_s.underscore.to_sym
10
+ end
11
+
12
+ block = Gretel::Crumbs.crumbs[key]
13
+ raise ArgumentError, "Breadcrumb :#{key} not found." unless block
14
+ @key = key
15
+ @context = context
16
+ instance_exec *args, &block
17
+ end
18
+
19
+ # Sets link of the breadcrumb.
20
+ # You can supply an optional options hash that will be available on the links
21
+ # so you can pass info when rendering the breadcrumbs manually.
22
+ #
23
+ # link "My Link", my_link_path
24
+ # link "Without URL"
25
+ # link "With Options", my_path, title: "Test", other: "Some other value"
26
+ def link(*args)
27
+ options = args.extract_options!
28
+ text, url = args
29
+
30
+ # Transform objects to real paths.
31
+ url = url_for(url) if url
32
+
33
+ links << Gretel::Link.new(key, text, url, options)
34
+ end
35
+
36
+ # Holds all of the breadcrumb's links as a breadcrumb can have multiple links.
37
+ def links
38
+ @links ||= []
39
+ end
40
+
41
+ # Sets or gets the parent breadcrumb.
42
+ # If you supply a parent key and optional arguments, it will set the parent.
43
+ # If nothing is supplied, it will return the parent, if this has been set.
44
+ #
45
+ # Example:
46
+ # parent :category, category
47
+ #
48
+ # Or short, which will infer the key from the model's `model_name`:
49
+ # parent category
50
+ def parent(*args)
51
+ return @parent if args.empty?
52
+ key = args.shift
53
+
54
+ @parent = Gretel::Crumb.new(context, key, *args)
55
+ end
56
+
57
+ # Key of the breadcrumb.
58
+ attr_reader :key
59
+
60
+ # The current view context.
61
+ attr_reader :context
62
+
63
+ # Proxy to view context.
64
+ def method_missing(method, *args, &block)
65
+ context.send(method, *args, &block)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,64 @@
1
+ module Gretel
2
+ module Crumbs
3
+ class << self
4
+ include Resettable
5
+
6
+ # Stores the supplied block for later use.
7
+ def crumb(key, &block)
8
+ crumbs[key] = block
9
+ end
10
+
11
+ # Returns a hash of all stored crumb blocks.
12
+ def crumbs
13
+ @crumbs ||= {}
14
+ end
15
+
16
+ # Returns true if a crumb with the given key has been set.
17
+ def crumb_defined?(key)
18
+ crumbs.has_key?(key)
19
+ end
20
+
21
+ # Loads the breadcrumb configuration files.
22
+ def load_breadcrumbs
23
+ @crumbs = {}
24
+
25
+ loaded_file_mtimes.clear
26
+ breadcrumb_files.each do |file|
27
+ instance_eval open(file).read, file
28
+ loaded_file_mtimes << File.mtime(file)
29
+ end
30
+
31
+ @loaded = true
32
+ end
33
+
34
+ # Reloads the breadcrumb configuration files if they have changed.
35
+ def reload_if_needed
36
+ load_breadcrumbs if reload?
37
+ end
38
+
39
+ # Returns true if a breadcrumbs reload is needed based on configuration file changes.
40
+ def reload?
41
+ return true unless loaded?
42
+ return false unless Gretel.reload_environments.include?(Rails.env)
43
+
44
+ loaded_file_mtimes != breadcrumb_files.map { |file| File.mtime(file) }
45
+ end
46
+
47
+ # Returns true if the breadcrumb configuration files have been loaded.
48
+ def loaded?
49
+ !!@loaded
50
+ end
51
+
52
+ # List of breadcrumb configuration files.
53
+ def breadcrumb_files
54
+ Dir[*Gretel.breadcrumb_paths]
55
+ end
56
+
57
+ private
58
+
59
+ def loaded_file_mtimes
60
+ @loaded_file_mtimes ||= []
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + "/deprecated/*.rb"].each { |file| require file }
@@ -0,0 +1,25 @@
1
+ if RUBY_VERSION < "2.0"
2
+ Gretel::Renderer.class_eval do
3
+ def options_for_style_with_default_style_key(style_key)
4
+ if style_key == :default
5
+ Gretel.show_deprecation_warning "The :default style key is now called :inline. Please use `breadcrumbs style: :inline` instead or omit it, as it is the default."
6
+ style_key = :inline
7
+ end
8
+ options_for_style_without_default_style_key(style_key)
9
+ end
10
+
11
+ alias_method_chain :options_for_style, :default_style_key
12
+ end
13
+ else
14
+ module DeprecatedDefaultStyleKey
15
+ def options_for_style(style_key)
16
+ if style_key == :default
17
+ Gretel.show_deprecation_warning "The :default style key is now called :inline. Please use `breadcrumbs style: :inline` instead or omit it, as it is the default."
18
+ style_key = :inline
19
+ end
20
+ super(style_key)
21
+ end
22
+ end
23
+
24
+ Gretel::Renderer.send :prepend, DeprecatedDefaultStyleKey
25
+ end
@@ -0,0 +1,15 @@
1
+ Gretel::Crumbs.class_eval do
2
+ class << self
3
+ # Was used to lay out breadcrumbs in an initializer. Deprecated since v2.1.0
4
+ # and removed in v3.0.0. Will raise an exception if used. Put breadcrumbs in
5
+ # +config/breadcrumbs.rb+ instead (see
6
+ # https://github.com/lassebunk/gretel/blob/master/README.md for details).
7
+ def layout(&block)
8
+ raise (
9
+ "Gretel::Crumbs.layout was removed in Gretel version 3.0. " +
10
+ "Please put your breadcrumbs in `config/breadcrumbs.rb`. " +
11
+ "This will also automatically reload your breadcrumbs when you change them in the development environment. " +
12
+ "See https://github.com/lassebunk/gretel/blob/master/README.md for details.")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ if RUBY_VERSION < "2.0"
2
+ Gretel::Renderer.class_eval do
3
+ def options_for_render_with_show_root_alone(options = {})
4
+ options = options_for_render_without_show_root_alone(options)
5
+ if show_root_alone = options.delete(:show_root_alone)
6
+ Gretel.show_deprecation_warning "The :show_root_alone option is deprecated and will be removed in Gretel v4.0.0. Use `breadcrumbs(display_single_fragment: #{show_root_alone.inspect})` instead."
7
+ options[:display_single_fragment] = show_root_alone
8
+ end
9
+ options
10
+ end
11
+
12
+ alias_method_chain :options_for_render, :show_root_alone
13
+ end
14
+ else
15
+ module DeprecatedShowRootAlone
16
+ def options_for_render(options = {})
17
+ options = super(options)
18
+ if show_root_alone = options.delete(:show_root_alone)
19
+ Gretel.show_deprecation_warning "The :show_root_alone option is deprecated and will be removed in Gretel v4.0.0. Use `breadcrumbs(display_single_fragment: #{show_root_alone.inspect})` instead."
20
+ options[:display_single_fragment] = show_root_alone
21
+ end
22
+ options
23
+ end
24
+ end
25
+
26
+ Gretel::Renderer.send :prepend, DeprecatedShowRootAlone
27
+ end