dat_gretel 4.0.1

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 (76) 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 +359 -0
  8. data/Rakefile +10 -0
  9. data/dat_gretel.gemspec +22 -0
  10. data/gemfiles/Gemfile-rails.3.1.x +19 -0
  11. data/gemfiles/Gemfile-rails.3.2.x +19 -0
  12. data/gemfiles/Gemfile-rails.4.0.x +19 -0
  13. data/gemfiles/Gemfile-rails.4.1.x +19 -0
  14. data/gemfiles/Gemfile-rails.5.2.x +19 -0
  15. data/lib/dat_gretel.rb +82 -0
  16. data/lib/dat_gretel/crumb.rb +70 -0
  17. data/lib/dat_gretel/crumbs.rb +64 -0
  18. data/lib/dat_gretel/deprecated.rb +1 -0
  19. data/lib/dat_gretel/deprecated/default_style_key.rb +25 -0
  20. data/lib/dat_gretel/deprecated/layout.rb +15 -0
  21. data/lib/dat_gretel/deprecated/show_root_alone.rb +27 -0
  22. data/lib/dat_gretel/deprecated/yield_links.rb +44 -0
  23. data/lib/dat_gretel/link.rb +40 -0
  24. data/lib/dat_gretel/renderer.rb +259 -0
  25. data/lib/dat_gretel/resettable.rb +13 -0
  26. data/lib/dat_gretel/version.rb +3 -0
  27. data/lib/dat_gretel/view_helpers.rb +71 -0
  28. data/lib/generators/dat_gretel/USAGE +8 -0
  29. data/lib/generators/dat_gretel/install_generator.rb +12 -0
  30. data/lib/generators/dat_gretel/templates/breadcrumbs.rb +28 -0
  31. data/test/dat_gretel_test.rb +24 -0
  32. data/test/deprecated_test.rb +45 -0
  33. data/test/dummy/Rakefile +7 -0
  34. data/test/dummy/app/assets/javascripts/application.js +15 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/test/dummy/app/controllers/application_controller.rb +3 -0
  37. data/test/dummy/app/helpers/application_helper.rb +5 -0
  38. data/test/dummy/app/mailers/.gitkeep +0 -0
  39. data/test/dummy/app/models/.gitkeep +0 -0
  40. data/test/dummy/app/models/issue.rb +3 -0
  41. data/test/dummy/app/models/project.rb +3 -0
  42. data/test/dummy/app/views/breadcrumbs/site.rb +3 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/config/application.rb +14 -0
  45. data/test/dummy/config/boot.rb +10 -0
  46. data/test/dummy/config/breadcrumbs.rb +3 -0
  47. data/test/dummy/config/breadcrumbs/test_crumbs.rb +85 -0
  48. data/test/dummy/config/database.yml +25 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/development.rb +2 -0
  51. data/test/dummy/config/environments/production.rb +2 -0
  52. data/test/dummy/config/environments/test.rb +2 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/inflections.rb +15 -0
  55. data/test/dummy/config/initializers/mime_types.rb +5 -0
  56. data/test/dummy/config/initializers/secret_token.rb +7 -0
  57. data/test/dummy/config/initializers/session_store.rb +8 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/locales/en.yml +5 -0
  60. data/test/dummy/config/routes.rb +11 -0
  61. data/test/dummy/db/migrate/20130122163007_create_projects.rb +9 -0
  62. data/test/dummy/db/migrate/20130122163051_create_issues.rb +10 -0
  63. data/test/dummy/db/schema.rb +28 -0
  64. data/test/dummy/lib/assets/.gitkeep +0 -0
  65. data/test/dummy/log/.gitkeep +0 -0
  66. data/test/dummy/public/404.html +26 -0
  67. data/test/dummy/public/422.html +26 -0
  68. data/test/dummy/public/500.html +25 -0
  69. data/test/dummy/public/favicon.ico +0 -0
  70. data/test/dummy/script/rails +6 -0
  71. data/test/fixtures/issues.yml +4 -0
  72. data/test/fixtures/projects.yml +3 -0
  73. data/test/gretel_test.rb +24 -0
  74. data/test/helper_methods_test.rb +552 -0
  75. data/test/test_helper.rb +15 -0
  76. metadata +193 -0
@@ -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,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dat_gretel/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dat_gretel"
8
+ gem.version = DatGretel::VERSION
9
+ gem.authors = ["Lasse Bunk, Marcio Silva"]
10
+ gem.email = ["marcio.dat@gmail.com"]
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. This is a fork from the original original version from Lasse Bunk including updates and new functionalities}
13
+ gem.homepage = "http://github.com/marciodat/dat_gretel"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = gem.files.grep(%r{^test/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rails", ">= 4.1.0"
21
+ gem.add_development_dependency "sqlite3"
22
+ end
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "dat_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 "dat_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 "dat_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 "dat_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"
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "dat_gretel", :path => ".."
4
+
5
+ gem "rails", "~> 5.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,82 @@
1
+ require 'dat_gretel/version'
2
+ require 'dat_gretel/resettable'
3
+ require 'dat_gretel/crumbs'
4
+ require 'dat_gretel/crumb'
5
+ require 'dat_gretel/link'
6
+ require 'dat_gretel/renderer'
7
+ require 'dat_gretel/view_helpers'
8
+ require 'dat_gretel/deprecated'
9
+
10
+ module DatGretel
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 if defined? @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
+ DatGretel::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, DatGretel::ViewHelpers
@@ -0,0 +1,70 @@
1
+ module DatGretel
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
+
6
+ def initialize(context, key, *args)
7
+ if key.class.respond_to?(:model_name)
8
+ # Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
9
+ args.unshift key
10
+ key = key.class.model_name.to_s.underscore.to_sym
11
+ end
12
+
13
+ block = DatGretel::Crumbs.crumbs[key]
14
+ raise ArgumentError, "Breadcrumb :#{key} not found." unless block
15
+ @key = key
16
+ @context = context
17
+ @parent = nil
18
+ instance_exec(*args, &block)
19
+ end
20
+
21
+ # Sets link of the breadcrumb.
22
+ # You can supply an optional options hash that will be available on the links
23
+ # so you can pass info when rendering the breadcrumbs manually.
24
+ #
25
+ # link "My Link", my_link_path
26
+ # link "Without URL"
27
+ # link "With Options", my_path, title: "Test", other: "Some other value"
28
+ def link(*args)
29
+ options = args.extract_options!
30
+ text, url = args
31
+
32
+ # Transform objects to real paths.
33
+ url = url_for(url) if url
34
+
35
+ links << DatGretel::Link.new(key, text, url, options)
36
+ end
37
+
38
+ # Holds all of the breadcrumb's links as a breadcrumb can have multiple links.
39
+ def links
40
+ @links ||= []
41
+ end
42
+
43
+ # Sets or gets the parent breadcrumb.
44
+ # If you supply a parent key and optional arguments, it will set the parent.
45
+ # If nothing is supplied, it will return the parent, if this has been set.
46
+ #
47
+ # Example:
48
+ # parent :category, category
49
+ #
50
+ # Or short, which will infer the key from the model's `model_name`:
51
+ # parent category
52
+ def parent(*args)
53
+ return @parent if args.empty?
54
+ key = args.shift
55
+
56
+ @parent = DatGretel::Crumb.new(context, key, *args)
57
+ end
58
+
59
+ # Key of the breadcrumb.
60
+ attr_reader :key
61
+
62
+ # The current view context.
63
+ attr_reader :context
64
+
65
+ # Proxy to view context.
66
+ def method_missing(method, *args, &block)
67
+ context.send(method, *args, &block)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,64 @@
1
+ module DatGretel
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 DatGretel.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 if defined? @loaded
50
+ end
51
+
52
+ # List of breadcrumb configuration files.
53
+ def breadcrumb_files
54
+ Dir[*DatGretel.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
+ DatGretel::Renderer.class_eval do
3
+ def options_for_style_with_default_style_key(style_key)
4
+ if style_key == :default
5
+ DatGretel.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
+ DatGretel.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
+ DatGretel::Renderer.send :prepend, DeprecatedDefaultStyleKey
25
+ end
@@ -0,0 +1,15 @@
1
+ DatGretel::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
+ DatGretel::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
+ DatGretel.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
+ DatGretel.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
+ DatGretel::Renderer.send :prepend, DeprecatedShowRootAlone
27
+ end
@@ -0,0 +1,44 @@
1
+ if RUBY_VERSION < "2.0"
2
+ DatGretel::ViewHelpers.class_eval do
3
+
4
+ def breadcrumbs_with_yield_links(options = {})
5
+ if block_given?
6
+ DatGretel.show_deprecation_warning(
7
+ "Calling `breadcrumbs` with a block has been deprecated and will be removed in Gretel version 4.0. Please use `tap` instead. Example:\n" +
8
+ "\n" +
9
+ " breadcrumbs(autoroot: false).tap do |links|\n" +
10
+ " if links.any?\n" +
11
+ " # process links here\n" +
12
+ " end\n" +
13
+ " end\n"
14
+ )
15
+ yield gretel_renderer.render(options)
16
+ else
17
+ breadcrumbs_without_yield_links(options)
18
+ end
19
+ end
20
+
21
+ alias_method_chain :breadcrumbs, :yield_links
22
+ end
23
+ else
24
+ module DeprecatedYieldLinks
25
+ def breadcrumbs(options = {})
26
+ if block_given?
27
+ DatGretel.show_deprecation_warning(
28
+ "Calling `breadcrumbs` with a block has been deprecated and will be removed in Gretel version 4.0. Please use `tap` instead. Example:\n" +
29
+ "\n" +
30
+ " breadcrumbs(autoroot: false).tap do |links|\n" +
31
+ " if links.any?\n" +
32
+ " # process links here\n" +
33
+ " end\n" +
34
+ " end\n"
35
+ )
36
+ yield gretel_renderer.render(options)
37
+ else
38
+ super(options)
39
+ end
40
+ end
41
+ end
42
+
43
+ DatGretel::ViewHelpers.send :prepend, DeprecatedYieldLinks
44
+ end