File: gretel.rb

package info (click to toggle)
ruby-gretel 5.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188 kB
  • sloc: ruby: 458; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'gretel/version'
require 'gretel/resettable'
require 'gretel/railtie'

module Gretel
  class << self
    include Resettable

    # Returns the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+
    # in the app and all loaded engines. Breadcrumbs set in the app will override
    # breadcrumbs set in engines.
    def breadcrumb_paths
      @breadcrumb_paths ||= begin
        engines = Rails::Engine.subclasses.map(&:instance)

        engine_roots = engines.map { |e| e.config.root }
        
        [*engine_roots, Rails.root].map do |root|
          [root.join("config", "breadcrumbs.rb"),
           root.join("config", "breadcrumbs", "**", "*.rb"),
           root.join("app", "views", "breadcrumbs", "**", "*.rb")]
        end.flatten
      end
    end

    # Sets the path from with breadcrumbs are loaded. Default is +config/breadcrumbs.rb+.
    def breadcrumb_paths=(paths)
      @breadcrumb_paths = paths
    end

    # Array of Rails environment names with automatic configuration reload. Default is +["development"]+.
    def reload_environments
      @reload_environments ||= ["development"]
    end

    # Registers a style for later use.
    # 
    #   Gretel.register_style :ul, { container_tag: :ul, fragment_tag: :li }
    def register_style(style, options)
      Gretel::Renderer.register_style style, options
    end

    # Sets the Rails environment names with automatic configuration reload. Default is +["development"]+.
    attr_writer :reload_environments

    # Yields this +Gretel+ to be configured.
    # 
    #   Gretel.configure do |config|
    #     config.reload_environments << "staging"
    #   end
    def configure
      yield self
    end
  end
end