Skip to content

Commit

Permalink
+ SimpleNavigation.set_env
Browse files Browse the repository at this point in the history
  • Loading branch information
andi committed Aug 20, 2010
1 parent b96390d commit 1d785d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/simple_navigation.rb
Expand Up @@ -22,6 +22,12 @@ class << self
def_delegators :adapter, :request, :request_uri, :request_path, :context_for_eval, :current_page?
def_delegators :adapter_class, :init_framework

def set_env(root, environment)
self.root = root
self.environment = environment
self.config_file_paths ||= [SimpleNavigation.default_config_file_path]
end

def framework
return :rails if defined?(Rails)
return :sinatra if defined?(Sinatra)
Expand Down Expand Up @@ -74,7 +80,7 @@ def config_file_path=(path)
# Reads the config_file for the specified navigation_context and stores it for later evaluation.
def load_config(navigation_context = :default)
raise "Config file '#{config_file_name(navigation_context)}' not found in path(s) #{config_file_paths.join(', ')}!" unless config_file?(navigation_context)
if SimpleNavigation.environment == 'production'
if self.environment == 'production'
self.config_files[navigation_context] ||= IO.read(config_file(navigation_context))
else
self.config_files[navigation_context] = IO.read(config_file(navigation_context))
Expand Down
13 changes: 10 additions & 3 deletions lib/simple_navigation/adapters/rails.rb
Expand Up @@ -7,9 +7,8 @@ class Rails
attr_reader :controller, :template, :request

def self.init_framework
SimpleNavigation.root = rails3? ? ::Rails.root : ::RAILS_ROOT
SimpleNavigation.environment = rails3? ? ::Rails.env : ::RAILS_ENV
SimpleNavigation.config_file_paths ||= [SimpleNavigation.default_config_file_path]
SimpleNavigation.set_env(rails_root, rails_env)

ActionController::Base.send(:include, SimpleNavigation::ControllerMethods) if defined?(SimpleNavigation::ControllerMethods)
ActionController::Base.send(:include, SimpleNavigation::Helpers)
ActionController::Base.send(:helper_method, :render_navigation, :render_primary_navigation, :render_sub_navigation)
Expand Down Expand Up @@ -53,6 +52,14 @@ def content_tag(type, content, options={})

protected

def self.rails_root
rails3? ? ::Rails.root : ::RAILS_ROOT
end

def self.rails_env
rails3? ? ::Rails.env : ::RAILS_ENV
end

def self.rails3?
::Rails::VERSION::MAJOR == 3
end
Expand Down

0 comments on commit 1d785d5

Please sign in to comment.