lib/storefront/configuration.rb in storefront-0.3.2 vs lib/storefront/configuration.rb in storefront-0.5.0

- old
+ new

@@ -1,13 +1,26 @@ module Storefront + class << self + def configure(&block) + yield configuration + end + + def configuration + @configuration ||= Storefront::Configuration.new + end + end + class Configuration attr_accessor :field, + :component_suffix, :hint_class, :hint_tag, :label_class, :error_class, :error_tag, + :auto_id_nav, + :auto_id_form, :valid_class, :required_class, :required_abbr, :required_title, :optional_class, @@ -63,16 +76,19 @@ :remove_label, :always_include_hint_tag, :always_include_error_tag, :cycle_fields, :require_if_validates_presence, + :default_component_header_level, # localization :localize_with_inheritance, :localize_with_namespace, - :localize_with_nested_model + :localize_with_nested_model, + :meta_tags def initialize + @component_suffix = "widget" @hint_class = "hint" @hint_tag = :figure @label_class = "label" @required_class = "required" @required_abbr = "*" @@ -97,16 +113,17 @@ @collection_label_methods = %w(to_label display_name full_name name title to_s) @i18n_lookups_by_default = true @escape_html_entities_in_hints_and_labels = false @rename_nested_attributes = true @inline_validations = true + @auto_id_form = true @fieldset_class = "fieldset" @field_class = "field" @validate_class = "validate" @legend_class = "legend" @form_class = "form" - @id_enabled_on = [] # %w(field label error hint) + @id_enabled_on = ["input"] # %w(field label error hint) @widgets_path = "shared/widgets" @nav_class = "list-item" @include_aria = true @active_class = "active" @nav_tag = :li @@ -116,39 +133,70 @@ @term_value_class = "value" @hint_is_popup = false @list_tag = :ul @page_header_id = "header" @page_title_id = "title" + @auto_id_nav = false @page_subtitle_id = "subtitle" @widget_class = "widget" @header_class = "header" @title_class = "title" @subtitle_class = "subtitle" @content_class = "content" @default_header_level = 3 @term_separator = ":" - @rich_input = true + @rich_input = false @submit_fieldset_class = "submit-fieldset" @add_label = "+" @remove_label = "-" @cycle_fields = false @always_include_hint_tag = false @always_include_error_tag = true @require_if_validates_presence = true @localize_with_namespace = false @localize_with_nested_model = false @localize_with_inheritance = true + @default_component_header_level = 3 + @meta_tags = [ + :description, + :keywords, + :author, + :copyright, + :category, + :robots + ] end def get(key) send(key).respond_to?(:call) ? send(key).call : send(key) end def current_scope - Thread.current[:storefront_config] + Thread.current[:storefront] end def current_scope=(value) - Thread.current[:storefront_config] = value + Thread.current[:storefront] = value + end + + def configure_action_view + base = "#{File.expand_path(File.dirname(__FILE__))}/helpers" + Dir["#{base}/*"].each do |path| + next if File.directory?(path) + constant_name = File.basename(path, File.extname(path)).gsub("/", "::").camelize + ActionView::Base.send :include, "Storefront::Helpers::#{constant_name}".constantize + end + end + + def configure_action_controller + base = "#{File.expand_path(File.dirname(__FILE__))}/helpers" + Dir["#{base}/*"].each do |path| + next if File.directory?(path) || File.basename(path) =~ /(form|table|dashboard)/ + # need to do these as traditional helper declarations somehow + constant_name = File.basename(path, File.extname(path)).gsub("/", "::").camelize + ActionController::Base.send :include, "Storefront::Helpers::#{constant_name}".constantize + end + + ActionController::Base.send :before_filter, :configure_storefront end end end