nesta 0.13.0 → 0.14.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/.gitignore +1 -0
- data/CHANGES +73 -0
- data/Gemfile.lock +24 -22
- data/README.md +4 -2
- data/bin/nesta +4 -1
- data/lib/nesta/app.rb +1 -2
- data/lib/nesta/commands/build.rb +38 -0
- data/lib/nesta/commands/new.rb +2 -1
- data/lib/nesta/commands.rb +1 -0
- data/lib/nesta/config.rb +49 -75
- data/lib/nesta/config_file.rb +5 -1
- data/lib/nesta/helpers.rb +0 -5
- data/lib/nesta/models.rb +33 -34
- data/lib/nesta/navigation.rb +0 -5
- data/lib/nesta/overrides.rb +32 -43
- data/lib/nesta/plugin.rb +0 -16
- data/lib/nesta/static/assets.rb +50 -0
- data/lib/nesta/static/html_file.rb +26 -0
- data/lib/nesta/static/site.rb +104 -0
- data/lib/nesta/version.rb +1 -1
- data/lib/nesta.rb +1 -3
- data/nesta.gemspec +4 -4
- data/templates/config/config.yml +28 -2
- data/templates/themes/README.md +1 -1
- data/templates/themes/views/master.sass +1 -1
- data/test/integration/atom_feed_test.rb +1 -1
- data/test/integration/commands/build_test.rb +53 -0
- data/test/integration/overrides_test.rb +1 -1
- data/test/integration/sitemap_test.rb +1 -1
- data/test/support/temporary_files.rb +1 -1
- data/test/support/test_configuration.rb +2 -4
- data/test/unit/config_test.rb +25 -94
- data/test/unit/static/assets_test.rb +56 -0
- data/test/unit/static/html_file_test.rb +41 -0
- data/test/unit/static/site_test.rb +104 -0
- data/views/atom.haml +2 -2
- data/views/comments.haml +2 -2
- data/views/footer.haml +1 -1
- data/views/header.haml +2 -3
- data/views/layout.haml +2 -2
- data/views/master.sass +1 -1
- data/views/mixins.sass +2 -2
- data/views/normalize.scss +0 -1
- data/views/sitemap.haml +1 -1
- metadata +33 -25
data/lib/nesta/overrides.rb
CHANGED
@@ -1,30 +1,47 @@
|
|
1
1
|
module Nesta
|
2
2
|
module Overrides
|
3
3
|
module Renderers
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
def find_template(views, name, engine, &block)
|
5
|
+
user_paths = [
|
6
|
+
Nesta::Overrides.local_view_path,
|
7
|
+
Nesta::Overrides.theme_view_path,
|
8
|
+
views
|
9
|
+
].flatten.compact
|
10
|
+
user_paths.each do |path|
|
11
|
+
super(path, name, engine, &block)
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def scss(template, options = {}, locals = {})
|
15
|
-
|
16
|
-
|
16
|
+
find_template(Nesta::App.settings.views, template, Tilt::ScssTemplate) do |file|
|
17
|
+
return Tilt.new(file).render if File.exist?(file)
|
18
|
+
end
|
19
|
+
raise IOError, "SCSS template not found: #{template}"
|
17
20
|
end
|
18
21
|
|
19
22
|
def sass(template, options = {}, locals = {})
|
20
|
-
|
21
|
-
|
23
|
+
find_template(Nesta::App.settings.views, template, Tilt::SassTemplate) do |file|
|
24
|
+
return Tilt.new(file).render if File.exist?(file)
|
25
|
+
end
|
26
|
+
raise IOError, "Sass template not found: #{template}"
|
22
27
|
end
|
23
28
|
|
24
29
|
def stylesheet(template, options = {}, locals = {})
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
scss(template, options, locals)
|
31
|
+
rescue IOError
|
32
|
+
sass(template, options, locals)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.local_view_path
|
37
|
+
Nesta::Path.local("views")
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.theme_view_path
|
41
|
+
if Nesta::Config.theme.nil?
|
42
|
+
nil
|
43
|
+
else
|
44
|
+
Nesta::Path.themes(Nesta::Config.theme, "views")
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|
@@ -39,33 +56,5 @@ module Nesta
|
|
39
56
|
require app_file if File.exist?(app_file)
|
40
57
|
end
|
41
58
|
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def self.template_exists?(engine, views, template)
|
45
|
-
views && File.exist?(File.join(views, "#{template}.#{engine}"))
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.render_options(template, *engines)
|
49
|
-
[local_view_path, theme_view_path].each do |path|
|
50
|
-
engines.each do |engine|
|
51
|
-
if template_exists?(engine, path, template)
|
52
|
-
return { views: path }, engine
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
[{}, :sass]
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.local_view_path
|
60
|
-
Nesta::Path.local("views")
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.theme_view_path
|
64
|
-
if Nesta::Config.theme.nil?
|
65
|
-
nil
|
66
|
-
else
|
67
|
-
Nesta::Path.themes(Nesta::Config.theme, "views")
|
68
|
-
end
|
69
|
-
end
|
70
59
|
end
|
71
60
|
end
|
data/lib/nesta/plugin.rb
CHANGED
@@ -15,21 +15,5 @@ module Nesta
|
|
15
15
|
def self.initialize_plugins
|
16
16
|
self.loaded.each { |name| require "#{name}/init" }
|
17
17
|
end
|
18
|
-
|
19
|
-
def self.load_local_plugins
|
20
|
-
# This approach is deprecated; plugins should now be distributed
|
21
|
-
# as gems. See http://nestacms.com/docs/plugins/writing-plugins
|
22
|
-
plugins = Dir.glob(File.expand_path('../plugins/*', File.dirname(__FILE__)))
|
23
|
-
plugins.each { |path| require_local_plugin(path) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.require_local_plugin(path)
|
27
|
-
Nesta.deprecated(
|
28
|
-
'loading plugins from ./plugins', "convert #{path} to a gem")
|
29
|
-
require File.join(path, 'lib', File.basename(path))
|
30
|
-
rescue LoadError => e
|
31
|
-
$stderr.write("Couldn't load plugins/#{File.basename(path)}: #{e}\n")
|
32
|
-
end
|
33
|
-
private_class_method :require_local_plugin
|
34
18
|
end
|
35
19
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
module Nesta
|
4
|
+
module Static
|
5
|
+
class Assets
|
6
|
+
def initialize(build_dir, logger = nil)
|
7
|
+
@build_dir = build_dir
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_attachments
|
12
|
+
dest_basename = File.basename(Nesta::Config.attachment_path)
|
13
|
+
dest_dir = File.join(@build_dir, dest_basename)
|
14
|
+
copy_file_tree(Nesta::Config.attachment_path, dest_dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_public_folder
|
18
|
+
copy_file_tree(Nesta::App.settings.public_folder, @build_dir)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def log(message)
|
24
|
+
@logger.call(message) if @logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_file_tree(source_dir, dest_dir)
|
28
|
+
files_in_tree(source_dir).each do |file|
|
29
|
+
target = File.join(dest_dir, file.sub(/^#{source_dir}\//, ''))
|
30
|
+
task = Rake::FileTask.define_task(target => file) do
|
31
|
+
target_dir = File.dirname(target)
|
32
|
+
FileUtils.mkdir_p(target_dir) unless Dir.exist?(target_dir)
|
33
|
+
FileUtils.cp(file, target_dir)
|
34
|
+
log("Copied #{file} to #{target}")
|
35
|
+
end
|
36
|
+
task.invoke
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def files_in_tree(directory)
|
41
|
+
Rake::FileList["#{directory}/**/*"].tap do |assets|
|
42
|
+
assets.exclude('~*')
|
43
|
+
assets.exclude do |f|
|
44
|
+
File.directory?(f)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Static
|
3
|
+
class HtmlFile
|
4
|
+
def initialize(build_dir, page)
|
5
|
+
@build_dir = build_dir
|
6
|
+
@content_path = page.filename
|
7
|
+
end
|
8
|
+
|
9
|
+
def page_shares_path_with_directory?(dir, base_without_ext)
|
10
|
+
Dir.exist?(File.join(dir, base_without_ext))
|
11
|
+
end
|
12
|
+
|
13
|
+
def filename
|
14
|
+
dir, base = File.split(@content_path)
|
15
|
+
base_without_ext = File.basename(base, File.extname(base))
|
16
|
+
subdir = dir.sub(/^#{Nesta::Config.page_path}/, '')
|
17
|
+
path = File.join(@build_dir, subdir, base_without_ext)
|
18
|
+
if page_shares_path_with_directory?(dir, base_without_ext)
|
19
|
+
File.join(path, 'index.html')
|
20
|
+
else
|
21
|
+
path + '.html'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
require_relative './html_file'
|
4
|
+
|
5
|
+
module Nesta
|
6
|
+
module Static
|
7
|
+
class Site
|
8
|
+
def initialize(build_dir, domain, logger = nil)
|
9
|
+
@build_dir = build_dir
|
10
|
+
@domain = domain
|
11
|
+
@logger = logger
|
12
|
+
@app = Nesta::App.new
|
13
|
+
set_app_root
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_pages
|
17
|
+
Nesta::Page.find_all.each do |page|
|
18
|
+
target = HtmlFile.new(@build_dir, page).filename
|
19
|
+
source = page.filename
|
20
|
+
task = Rake::FileTask.define_task(target => source) do
|
21
|
+
save_markup(target, render(page.abspath, target, source))
|
22
|
+
end
|
23
|
+
task.invoke
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_not_found
|
28
|
+
path_info = '/404'
|
29
|
+
source = 'no-such-file.md'
|
30
|
+
target = File.join(@build_dir, '404.html')
|
31
|
+
markup = render(path_info, target, source, expected_code: 404)
|
32
|
+
save_markup(target, markup)
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_atom_feed
|
36
|
+
filename = 'articles.xml'
|
37
|
+
path_info = "/#{filename}"
|
38
|
+
description = 'Atom feed'
|
39
|
+
target = File.join(@build_dir, filename)
|
40
|
+
markup = render(path_info, target, description)
|
41
|
+
save_markup(target, markup)
|
42
|
+
end
|
43
|
+
|
44
|
+
def render_sitemap
|
45
|
+
filename = File.join(@build_dir, 'sitemap.xml')
|
46
|
+
save_markup(filename, render('/sitemap.xml', filename, 'site'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def render_templated_assets
|
50
|
+
Nesta::Config.build.fetch('templated_assets', []).each do |path|
|
51
|
+
filename = File.join(@build_dir, path)
|
52
|
+
save_markup(filename, render(path, filename, path))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def log(message)
|
59
|
+
@logger.call(message) if @logger
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_app_root
|
63
|
+
root = ::File.expand_path('.')
|
64
|
+
['Gemfile', ].each do |expected|
|
65
|
+
if ! File.exist?(File.join(root, 'config', 'config.yml'))
|
66
|
+
message = "is this a Nesta site? (expected './#{expected}')"
|
67
|
+
raise RuntimeError, message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
Nesta::App.root = root
|
71
|
+
end
|
72
|
+
|
73
|
+
def rack_environment(abspath)
|
74
|
+
{
|
75
|
+
'REQUEST_METHOD' => 'GET',
|
76
|
+
'SCRIPT_NAME' => '',
|
77
|
+
'PATH_INFO' => abspath,
|
78
|
+
'QUERY_STRING' => '',
|
79
|
+
'SERVER_NAME' => @domain,
|
80
|
+
'SERVER_PROTOCOL' => 'https',
|
81
|
+
'rack.url_scheme' => 'https',
|
82
|
+
'rack.input' => StringIO.new,
|
83
|
+
'rack.errors' => STDERR
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def render(abspath, filename, description, expected_code: 200)
|
88
|
+
http_code, headers, body = @app.call(rack_environment(abspath))
|
89
|
+
if http_code != expected_code
|
90
|
+
raise RuntimeError, "Can't render #{filename} from #{description}"
|
91
|
+
end
|
92
|
+
body.join
|
93
|
+
end
|
94
|
+
|
95
|
+
def save_markup(filename, content)
|
96
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
97
|
+
if (! File.exist?(filename)) || (open(filename, 'r').read != content)
|
98
|
+
open(filename, 'w') { |output| output.write(content) }
|
99
|
+
log("Rendered #{filename}")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/nesta/version.rb
CHANGED
data/lib/nesta.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Nesta
|
2
2
|
def self.deprecated(name, message)
|
3
|
-
|
4
|
-
$stderr.puts "DEPRECATION WARNING: #{name} is deprecated; #{message}"
|
5
|
-
end
|
3
|
+
$stderr.puts "DEPRECATION WARNING: #{name} is deprecated; #{message}"
|
6
4
|
end
|
7
5
|
|
8
6
|
def self.fail_with(message)
|
data/nesta.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Graham Ashton"]
|
10
10
|
s.email = ["graham@effectif.com"]
|
11
|
-
s.homepage = "
|
11
|
+
s.homepage = "https://nestacms.com"
|
12
12
|
s.summary = %q{Ruby CMS, written in Sinatra}
|
13
13
|
s.description = <<-EOF
|
14
14
|
Nesta is a lightweight Content Management System, written in Ruby using
|
@@ -31,10 +31,11 @@ EOF
|
|
31
31
|
|
32
32
|
s.add_dependency('haml', '>= 3.1', '< 6.0')
|
33
33
|
s.add_dependency('haml-contrib', '>= 1.0')
|
34
|
-
s.add_dependency('rack', '~> 2
|
34
|
+
s.add_dependency('rack', '~> 2')
|
35
|
+
s.add_dependency('rake')
|
35
36
|
s.add_dependency('rdiscount', '~> 2.1')
|
36
37
|
s.add_dependency('RedCloth', '~> 4.2')
|
37
|
-
s.add_dependency('
|
38
|
+
s.add_dependency('sass-embedded', '~> 1.58')
|
38
39
|
s.add_dependency('sinatra', '~> 2.0')
|
39
40
|
s.add_dependency('tilt', '~> 2.0')
|
40
41
|
|
@@ -46,5 +47,4 @@ EOF
|
|
46
47
|
s.add_development_dependency('capybara', '~> 2.0')
|
47
48
|
s.add_development_dependency('minitest', '~> 5.0')
|
48
49
|
s.add_development_dependency('minitest-reporters')
|
49
|
-
s.add_development_dependency('rake')
|
50
50
|
end
|
data/templates/config/config.yml
CHANGED
@@ -12,7 +12,7 @@ subtitle: "(change this text in config/config.yml)"
|
|
12
12
|
#
|
13
13
|
# author:
|
14
14
|
# name: Your Name
|
15
|
-
# uri:
|
15
|
+
# uri: https://yourdomain.com
|
16
16
|
# email: you@yourdomain.com
|
17
17
|
|
18
18
|
# You can stick with the default look and feel, or use a theme. Themes are
|
@@ -21,7 +21,7 @@ subtitle: "(change this text in config/config.yml)"
|
|
21
21
|
#
|
22
22
|
# theme: name-of-theme
|
23
23
|
|
24
|
-
# If you want to use the Disqus service (
|
24
|
+
# If you want to use the Disqus service (https://disqus.com) to display
|
25
25
|
# comments on your site, register a Disqus account and then specify your
|
26
26
|
# site's short name here. A comment form will automatically be added to
|
27
27
|
# the bottom of your pages.
|
@@ -65,3 +65,29 @@ content: content
|
|
65
65
|
# production:
|
66
66
|
# content: /var/apps/nesta/shared/content
|
67
67
|
# google_analytics_code: "UA-???????-?"
|
68
|
+
|
69
|
+
# The following settings control the behaviour of the `nesta build`
|
70
|
+
# command, which is used to generate a "static" version of your site.
|
71
|
+
# It's optional, but allows you to deploy your site on hosting providers
|
72
|
+
# that serve pre-prepared HTML and CSS files (instead of generating them
|
73
|
+
# in real-time with a web server).
|
74
|
+
#
|
75
|
+
# You can either set the `domain` key here, or specify it on the command
|
76
|
+
# line with the `--domain` switch. Nesta needs to know your site's
|
77
|
+
# domain name so that it can generate the correct URLs in sitemap.xml,
|
78
|
+
# and in your Atom feed.
|
79
|
+
#
|
80
|
+
# The templated_assets setting is a list of the things that Nesta
|
81
|
+
# generates for you, other from all the page in your content directory.
|
82
|
+
# The example below is for a site that has two stylesheets, both of
|
83
|
+
# which are converted from .sass or .scss files in your ./views folder.
|
84
|
+
#
|
85
|
+
# If you're not using Sass and are just editing CSS files directly, you
|
86
|
+
# can keep them in your ./public folder and Nesta's build command will
|
87
|
+
# find them automatically.
|
88
|
+
#
|
89
|
+
# build:
|
90
|
+
# domain: yourdomain.com
|
91
|
+
# templated_assets:
|
92
|
+
# - /css/master.css
|
93
|
+
# - /css/local.css
|
data/templates/themes/README.md
CHANGED
@@ -18,7 +18,7 @@ describe 'Atom feed' do
|
|
18
18
|
it "uses Atom's XML namespace" do
|
19
19
|
with_temp_content_directory do
|
20
20
|
visit_feed
|
21
|
-
assert_has_xpath '//feed[@xmlns="
|
21
|
+
assert_has_xpath '//feed[@xmlns="https://www.w3.org/2005/Atom"]'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_relative '../../../lib/nesta/commands'
|
3
|
+
|
4
|
+
describe 'nesta build' do
|
5
|
+
include ModelFactory
|
6
|
+
include TestConfiguration
|
7
|
+
|
8
|
+
def silencing_stdout(&block)
|
9
|
+
stdout, $stdout = $stdout, StringIO.new
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
$stdout.close
|
13
|
+
$stdout = stdout
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'builds HTML file from Markdown file' do
|
17
|
+
in_temporary_project do
|
18
|
+
with_temp_content_directory do
|
19
|
+
page = create(:page)
|
20
|
+
command = Nesta::Commands::Build.new('output_dir')
|
21
|
+
|
22
|
+
process = Minitest::Mock.new
|
23
|
+
silencing_stdout { command.execute(process) }
|
24
|
+
|
25
|
+
assert_exists_in_project File.join('output_dir', page.abspath + '.html')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'reads domain name from config file' do
|
31
|
+
domain = 'mysite.com'
|
32
|
+
|
33
|
+
in_temporary_project do
|
34
|
+
stub_config('build' => { 'domain' => domain }) do
|
35
|
+
command = Nesta::Commands::Build.new('output_dir')
|
36
|
+
|
37
|
+
assert_equal domain, command.domain
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'overrides domain name if set on command line' do
|
43
|
+
domain = 'mysite.com'
|
44
|
+
|
45
|
+
in_temporary_project do
|
46
|
+
stub_config('build' => { 'domain' => 'ignored.com' }) do
|
47
|
+
command = Nesta::Commands::Build.new('output_dir', 'domain' => domain)
|
48
|
+
|
49
|
+
assert_equal domain, command.domain
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -75,7 +75,7 @@ describe 'Overriding files in gem and themes' do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
it 'renders stylesheet in the
|
78
|
+
it 'renders stylesheet in the gem if no others found' do
|
79
79
|
in_nesta_project do
|
80
80
|
visit '/css/master.css'
|
81
81
|
assert_equal 200, page.status_code
|
@@ -31,7 +31,7 @@ describe 'XML sitemap' do
|
|
31
31
|
|
32
32
|
it 'has a urlset tag' do
|
33
33
|
for_site_with_page do
|
34
|
-
namespace = '
|
34
|
+
namespace = 'https://www.sitemaps.org/schemas/sitemap/0.9'
|
35
35
|
assert_has_xpath "//urlset[@xmlns='#{namespace}']"
|
36
36
|
end
|
37
37
|
end
|
@@ -22,7 +22,7 @@ module TemporaryFiles
|
|
22
22
|
def in_temporary_project(*args, &block)
|
23
23
|
FileUtils.mkdir_p(File.join(project_root, 'config'))
|
24
24
|
File.open(File.join(project_root, 'config', 'config.yml'), 'w').close
|
25
|
-
Dir.chdir(project_root) { yield }
|
25
|
+
Dir.chdir(project_root) { yield project_root }
|
26
26
|
ensure
|
27
27
|
remove_temp_directory
|
28
28
|
end
|
@@ -2,10 +2,8 @@ module TestConfiguration
|
|
2
2
|
include TemporaryFiles
|
3
3
|
|
4
4
|
def stub_config(config, &block)
|
5
|
-
Nesta::Config.stub(:
|
6
|
-
|
7
|
-
yield
|
8
|
-
end
|
5
|
+
Nesta::Config.instance.stub(:config, config) do
|
6
|
+
yield
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
data/test/unit/config_test.rb
CHANGED
@@ -3,11 +3,17 @@ require 'test_helper'
|
|
3
3
|
describe Nesta::Config do
|
4
4
|
include TestConfiguration
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
it 'cannot be instantiated directly' do
|
7
|
+
assert_raises(NoMethodError) { Nesta::Config.new }
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'exposes settings at the class level' do
|
11
|
+
Nesta::Config::SETTINGS.each do |setting|
|
12
|
+
assert Nesta::Config.respond_to?(setting), "should respond to '#{setting}'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'defines default value for "Read more"' do
|
11
17
|
assert_equal 'Continue reading', Nesta::Config.read_more
|
12
18
|
end
|
13
19
|
|
@@ -15,100 +21,34 @@ describe Nesta::Config do
|
|
15
21
|
assert_nil Nesta::Config.author
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'falls back to config.yml' do
|
25
|
-
stub_config('subtitle' => 'Subtitle in YAML file') do
|
26
|
-
assert_equal 'Subtitle in YAML file', Nesta::Config.subtitle
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'overrides config.yml' do
|
31
|
-
stub_config('title' => 'Title in YAML file') do
|
32
|
-
assert_equal @title, Nesta::Config.title
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'knows how to cope with boolean values' do
|
37
|
-
Nesta::Config.settings << 'a_boolean'
|
38
|
-
begin
|
39
|
-
ENV['NESTA_A_BOOLEAN'] = 'true'
|
40
|
-
assert_equal true, Nesta::Config.a_boolean, 'should be true'
|
41
|
-
ENV['NESTA_A_BOOLEAN'] = 'false'
|
42
|
-
assert_equal false, Nesta::Config.a_boolean, 'should be false'
|
43
|
-
ensure
|
44
|
-
Nesta::Config.settings.pop
|
45
|
-
ENV.delete('NESTA_A_BOOLEAN')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should return configured value for "Read more"' do
|
50
|
-
ENV['NESTA_READ_MORE'] = 'Read on'
|
51
|
-
begin
|
52
|
-
assert_equal 'Read on', Nesta::Config.read_more
|
53
|
-
ensure
|
54
|
-
ENV.delete('NESTA_READ_MORE')
|
55
|
-
end
|
24
|
+
it 'reads configuration from YAML' do
|
25
|
+
title = 'Site Title'
|
26
|
+
stub_config('subtitle' => title) do
|
27
|
+
assert_equal title, Nesta::Config.subtitle
|
56
28
|
end
|
29
|
+
end
|
57
30
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
ENV['NESTA_AUTHOR__URI'] = uri
|
31
|
+
it 'sets author hash from YAML' do
|
32
|
+
name = 'Name from YAML'
|
33
|
+
uri = 'URI from YAML'
|
34
|
+
stub_config('author' => { 'name' => name, 'uri' => uri }) do
|
63
35
|
assert_equal name, Nesta::Config.author['name']
|
64
36
|
assert_equal uri, Nesta::Config.author['uri']
|
65
37
|
assert Nesta::Config.author['email'].nil?, 'should be nil'
|
66
38
|
end
|
67
39
|
end
|
68
40
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
assert_equal @title, Nesta::Config.subtitle
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'sets author hash from YAML' do
|
81
|
-
name = 'Name from YAML'
|
82
|
-
uri = 'URI from YAML'
|
83
|
-
stub_config('author' => { 'name' => name, 'uri' => uri }) do
|
84
|
-
assert_equal name, Nesta::Config.author['name']
|
85
|
-
assert_equal uri, Nesta::Config.author['uri']
|
86
|
-
assert Nesta::Config.author['email'].nil?, 'should be nil'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'overrides top level settings with environment specific settings' do
|
91
|
-
config = {
|
92
|
-
'content' => 'general/path',
|
93
|
-
'test' => { 'content' => 'rack_env_specific/path' }
|
94
|
-
}
|
95
|
-
stub_config(config) do
|
96
|
-
assert_equal 'rack_env_specific/path', Nesta::Config.content
|
97
|
-
end
|
41
|
+
it 'overrides top level settings with environment specific settings' do
|
42
|
+
config = {
|
43
|
+
'content' => 'general/path',
|
44
|
+
'test' => { 'content' => 'rack_env_specific/path' }
|
45
|
+
}
|
46
|
+
stub_config(config) do
|
47
|
+
assert_equal 'rack_env_specific/path', Nesta::Config.content
|
98
48
|
end
|
99
49
|
end
|
100
50
|
|
101
51
|
describe 'Nesta::Config.fetch' do
|
102
|
-
it 'retrieves settings from environment' do
|
103
|
-
ENV['NESTA_MY_SETTING'] = 'value in ENV'
|
104
|
-
begin
|
105
|
-
assert_equal 'value in ENV', Nesta::Config.fetch('my_setting')
|
106
|
-
assert_equal 'value in ENV', Nesta::Config.fetch(:my_setting)
|
107
|
-
ensure
|
108
|
-
ENV.delete('NESTA_MY_SETTING')
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
52
|
it 'retrieves settings from YAML' do
|
113
53
|
stub_config('my_setting' => 'value in YAML') do
|
114
54
|
assert_equal 'value in YAML', Nesta::Config.fetch('my_setting')
|
@@ -125,14 +65,5 @@ describe Nesta::Config do
|
|
125
65
|
it 'allows default values to be set' do
|
126
66
|
assert_equal 'default', Nesta::Config.fetch('no such setting', 'default')
|
127
67
|
end
|
128
|
-
|
129
|
-
it 'copes with non-truthy boolean values' do
|
130
|
-
ENV['NESTA_SETTING'] = 'false'
|
131
|
-
begin
|
132
|
-
assert_equal false, Nesta::Config.fetch('setting')
|
133
|
-
ensure
|
134
|
-
ENV.delete('NESTA_SETTING')
|
135
|
-
end
|
136
|
-
end
|
137
68
|
end
|
138
69
|
end
|