Skip to content

Commit

Permalink
Moved Nesta::App.root to Nesta::Env.root.
Browse files Browse the repository at this point in the history
If you want to load Nesta inside another Ruby app you'll probably want
to store it in a directory other than the process's current directory.
To do so you'll need to set the root directory, and you have to do that
before nesta/app is loaded. Given that nesta/app was what defined
Nesta::App, this seemed like a daft place to store the root directory
setting.
  • Loading branch information
gma committed Aug 12, 2011
1 parent 57c0e29 commit 80fea7c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Expand Up @@ -13,6 +13,11 @@
* Bug fix: Removed trailing whitespace inside <a> tags generated by
the display_breadcrumbs() helper.

* Bug fix: Nesta::App.root couldn't be set until after nesta/app was
required. Odd that, as the only reason to want to change
Nesta::App.root would be before requiring nesta/app. Fixed by
creating Nesta::Env and moving root to there instead.

= 0.9.5 / (1 May 2011)

* Added --version option to nesta command (Christopher Lindblom).
Expand Down
4 changes: 2 additions & 2 deletions lib/nesta/app.rb
Expand Up @@ -83,11 +83,11 @@ def format_date(date)

def local_stylesheet?
Nesta.deprecated('local_stylesheet?', 'use local_stylesheet_link_tag')
File.exist?(File.expand_path('views/local.sass', Nesta::App.root))
File.exist?(File.expand_path('views/local.sass', Nesta::Env.root))
end

def local_stylesheet_link_tag(name)
pattern = File.expand_path("views/#{name}.s{a,c}ss", Nesta::App.root)
pattern = File.expand_path("views/#{name}.s{a,c}ss", Nesta::Env.root)
if Dir.glob(pattern).size > 0
haml_tag :link, :href => "/css/#{name}.css", :rel => "stylesheet"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/nesta/config.rb
Expand Up @@ -46,7 +46,7 @@ def self.attachment_path(basename = nil)
end

def self.yaml_path
File.expand_path('config/config.yml', Nesta::App.root)
File.expand_path('config/config.yml', Nesta::Env.root)
end

def self.from_environment(setting)
Expand Down
7 changes: 7 additions & 0 deletions lib/nesta/env.rb
@@ -0,0 +1,7 @@
module Nesta
class Env
class << self
attr_accessor :root
end
end
end
4 changes: 2 additions & 2 deletions lib/nesta/path.rb
@@ -1,11 +1,11 @@
module Nesta
class Path
def self.local(*args)
File.expand_path(File.join(args), Nesta::App.root)
File.expand_path(File.join(args), Nesta::Env.root)
end

def self.themes(*args)
File.expand_path(File.join('themes', *args), Nesta::App.root)
File.expand_path(File.join('themes', *args), Nesta::Env.root)
end
end
end
4 changes: 2 additions & 2 deletions spec/commands_spec.rb
Expand Up @@ -115,7 +115,7 @@ def rakefile_source
FileUtils.mkdir_p(File.dirname(@config_path))
Nesta::Config.stub!(:yaml_path).and_return(@config_path)
create_config_yaml('content: path/to/content')
Nesta::App.stub!(:root).and_return(@project_path)
Nesta::Env.stub!(:root).and_return(@project_path)
@repo_url = 'git://github.com/gma/nesta-demo-content.git'
@demo_path = project_path('content-demo')
@command = Nesta::Commands::Demo::Content.new
Expand Down Expand Up @@ -265,7 +265,7 @@ def should_exist(file)
end

before(:each) do
Nesta::App.stub!(:root).and_return(FixtureHelper::FIXTURE_DIR)
Nesta::Env.stub!(:root).and_return(FixtureHelper::FIXTURE_DIR)
@name = 'my-new-theme'
Nesta::Commands::Theme::Create.new(@name).execute
end
Expand Down
6 changes: 3 additions & 3 deletions spec/overrides_spec.rb
Expand Up @@ -27,16 +27,16 @@ def create_app_file(type)
end

before(:each) do
@app_root = Nesta::App.root
Nesta::App.root = File.expand_path('fixtures/tmp', File.dirname(__FILE__))
@app_root = Nesta::Env.root
Nesta::Env.root = File.expand_path('fixtures/tmp', File.dirname(__FILE__))
@theme = 'my-theme'
@fixtures = []
stub_configuration
end

after(:each) do
@fixtures.each { |path| FileUtils.rm(path) if File.exist?(path) }
Nesta::App.root = @app_root
Nesta::Env.root = @app_root
end

describe "when local files exist" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -18,6 +18,7 @@ class App < Sinatra::Base
end
end

require File.expand_path('../lib/nesta/env', File.dirname(__FILE__))
require File.expand_path('../lib/nesta/app', File.dirname(__FILE__))

module FixtureHelper
Expand Down
5 changes: 3 additions & 2 deletions templates/config.ru
Expand Up @@ -3,7 +3,8 @@ require 'bundler/setup'

Bundler.require(:default)

require 'nesta/app'
require 'nesta/env'
Nesta::Env.root = ::File.expand_path('.', ::File.dirname(__FILE__))

Nesta::App.root = ::File.expand_path('.', ::File.dirname(__FILE__))
require 'nesta/app'
run Nesta::App

0 comments on commit 80fea7c

Please sign in to comment.