nesta 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +1 -1
  3. data/.gitignore +1 -0
  4. data/{CHANGES → CHANGELOG.md} +117 -21
  5. data/Gemfile.lock +28 -26
  6. data/LICENSE +1 -1
  7. data/README.md +45 -31
  8. data/RELEASING.md +1 -1
  9. data/bin/nesta +4 -1
  10. data/lib/nesta/app.rb +1 -2
  11. data/lib/nesta/commands/build.rb +38 -0
  12. data/lib/nesta/commands/new.rb +2 -1
  13. data/lib/nesta/commands.rb +1 -0
  14. data/lib/nesta/config.rb +49 -75
  15. data/lib/nesta/config_file.rb +5 -1
  16. data/lib/nesta/helpers.rb +0 -5
  17. data/lib/nesta/models/file_model.rb +191 -0
  18. data/lib/nesta/models/menu.rb +67 -0
  19. data/lib/nesta/models/page.rb +167 -0
  20. data/lib/nesta/models.rb +3 -422
  21. data/lib/nesta/navigation.rb +0 -5
  22. data/lib/nesta/overrides.rb +32 -43
  23. data/lib/nesta/plugin.rb +0 -16
  24. data/lib/nesta/static/assets.rb +50 -0
  25. data/lib/nesta/static/html_file.rb +26 -0
  26. data/lib/nesta/static/site.rb +104 -0
  27. data/lib/nesta/version.rb +1 -1
  28. data/lib/nesta.rb +1 -3
  29. data/nesta.gemspec +5 -5
  30. data/templates/config/config.yml +28 -2
  31. data/templates/themes/README.md +1 -1
  32. data/templates/themes/views/master.sass +1 -1
  33. data/test/integration/atom_feed_test.rb +1 -1
  34. data/test/integration/commands/build_test.rb +53 -0
  35. data/test/integration/overrides_test.rb +1 -1
  36. data/test/integration/sitemap_test.rb +1 -1
  37. data/test/support/temporary_files.rb +1 -1
  38. data/test/support/test_configuration.rb +2 -4
  39. data/test/unit/config_test.rb +25 -94
  40. data/test/unit/static/assets_test.rb +56 -0
  41. data/test/unit/static/html_file_test.rb +41 -0
  42. data/test/unit/static/site_test.rb +104 -0
  43. data/views/atom.haml +2 -2
  44. data/views/comments.haml +2 -2
  45. data/views/footer.haml +1 -1
  46. data/views/header.haml +2 -3
  47. data/views/layout.haml +2 -2
  48. data/views/master.sass +1 -1
  49. data/views/mixins.sass +2 -2
  50. data/views/normalize.scss +0 -1
  51. data/views/sitemap.haml +1 -1
  52. metadata +42 -31
  53. /data/test/unit/{file_model_test.rb → models/file_model_test.rb} +0 -0
  54. /data/test/unit/{menu_test.rb → models/menu_test.rb} +0 -0
  55. /data/test/unit/{page_test.rb → models/page_test.rb} +0 -0
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Nesta
2
- VERSION = '0.13.0'
2
+ VERSION = '0.15.0'
3
3
  end
data/lib/nesta.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Nesta
2
2
  def self.deprecated(name, message)
3
- if Nesta::App.environment != :test
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 = "http://nestacms.com"
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,11 +31,12 @@ 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.0')
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('sassc', '>= 2.2')
38
- s.add_dependency('sinatra', '~> 2.0')
38
+ s.add_dependency('sass-embedded', '~> 1.58')
39
+ s.add_dependency('sinatra', '~> 3.0')
39
40
  s.add_dependency('tilt', '~> 2.0')
40
41
 
41
42
  # Useful in development
@@ -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
@@ -12,7 +12,7 @@ subtitle: "(change this text in config/config.yml)"
12
12
  #
13
13
  # author:
14
14
  # name: Your Name
15
- # uri: http://yourhomepage.com
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 (http://disqus.com) to display
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
@@ -4,4 +4,4 @@
4
4
  <%= @name %> is a theme for Nesta, a [Ruby CMS](nesta), designed by
5
5
  <insert your name here>.
6
6
 
7
- [nesta]: http://nestacms.com
7
+ [nesta]: https://nestacms.com
@@ -1,3 +1,3 @@
1
1
  // Master Sass stylesheet
2
- // http://sass-lang.com/
2
+ // https://sass-lang.com/
3
3
 
@@ -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="http://www.w3.org/2005/Atom"]'
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 the gem if no others found' do
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 = 'http://www.sitemaps.org/schemas/sitemap/0.9'
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(:yaml_exists?, true) do
6
- Nesta::Config.stub(:yaml_conf, config) do
7
- yield
8
- end
5
+ Nesta::Config.instance.stub(:config, config) do
6
+ yield
9
7
  end
10
8
  end
11
9
 
@@ -3,11 +3,17 @@ require 'test_helper'
3
3
  describe Nesta::Config do
4
4
  include TestConfiguration
5
5
 
6
- after do
7
- ENV.keys.each { |variable| ENV.delete(variable) if variable =~ /NESTA_/ }
6
+ it 'cannot be instantiated directly' do
7
+ assert_raises(NoMethodError) { Nesta::Config.new }
8
8
  end
9
9
 
10
- it 'returns default value for "Read more"' do
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
- describe 'when settings defined in ENV' do
19
- before do
20
- @title = 'Title from ENV'
21
- ENV['NESTA_TITLE'] = @title
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
- it 'sets author hash from ENV' do
59
- name = 'Name from ENV'
60
- uri = 'URI from ENV'
61
- ENV['NESTA_AUTHOR__NAME'] = name
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
- describe 'when settings only defined in config.yml' do
70
- before do
71
- @title = 'Title in YAML file'
72
- end
73
-
74
- it 'reads configuration from YAML' do
75
- stub_config('subtitle' => @title) do
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
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ require_relative '../../../lib/nesta/static/assets'
4
+
5
+ describe 'Assets' do
6
+ include TestConfiguration
7
+
8
+ after do
9
+ remove_temp_directory
10
+ end
11
+
12
+ it 'is happy if attachments directory not present' do
13
+ in_temporary_project do |project_root|
14
+ stub_config('content' => File.join(project_root, 'content')) do
15
+ Nesta::Static::Assets.new('dist').copy_attachments
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'copies attachments into build directory' do
21
+ build_dir = 'dist'
22
+ attachment = 'image.jpeg'
23
+
24
+ in_temporary_project do |project_root|
25
+ stub_config('content' => File.join(project_root, 'content')) do
26
+ FileUtils.mkdir_p(Nesta::Config.attachment_path)
27
+ open(File.join(Nesta::Config.attachment_path, attachment), 'w')
28
+
29
+ Nesta::Static::Assets.new(build_dir).copy_attachments
30
+
31
+ assert_exists_in_project File.join(build_dir, 'attachments', attachment)
32
+ end
33
+ end
34
+ end
35
+
36
+ it 'is happy if public directory not present' do
37
+ in_temporary_project do |project_root|
38
+ Nesta::Static::Assets.new('dist').copy_public_folder
39
+ end
40
+ end
41
+
42
+ it 'copies contents of public directory into build directory' do
43
+ build_dir = 'dist'
44
+ asset_path = File.join('css', 'third-party.css')
45
+
46
+ in_temporary_project do |project_root|
47
+ public_path = File.join(project_root, 'public')
48
+ FileUtils.mkdir_p(File.dirname(File.join(public_path, asset_path)))
49
+ open(File.join(public_path, asset_path), 'w')
50
+
51
+ Nesta::Static::Assets.new(build_dir).copy_public_folder
52
+
53
+ assert_exists_in_project File.join(build_dir, asset_path)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ require_relative '../../../lib/nesta/static/html_file'
4
+
5
+ describe 'HtmlFile' do
6
+ include ModelFactory
7
+ include TestConfiguration
8
+
9
+ after do
10
+ remove_temp_directory
11
+ end
12
+
13
+ it 'determines HTML filename from build dir and page filename' do
14
+ build_dir = "dist"
15
+
16
+ with_temp_content_directory do
17
+ page = create(:page)
18
+
19
+ html_file = Nesta::Static::HtmlFile.new(build_dir, page)
20
+
21
+ expected = File.join(build_dir, "page-1.html")
22
+ assert_equal expected, html_file.filename
23
+ end
24
+ end
25
+
26
+ it 'creates index.html in directory if page shares path with directory' do
27
+ build_dir = "dist"
28
+
29
+ with_temp_content_directory do
30
+ page = create(:page)
31
+ ext = File.extname(page.filename)
32
+ directory_path = page.filename.sub(/#{ext}$/, '')
33
+ FileUtils.mkdir(directory_path)
34
+
35
+ html_file = Nesta::Static::HtmlFile.new(build_dir, page)
36
+
37
+ expected = File.join(build_dir, "page-1", "index.html")
38
+ assert_equal expected, html_file.filename
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ require_relative '../../../lib/nesta/static/site'
4
+
5
+ describe 'Site' do
6
+ include ModelFactory
7
+ include TestConfiguration
8
+
9
+ after do
10
+ remove_temp_directory
11
+ end
12
+
13
+ it 'converts Markdown to HTML' do
14
+ build_dir = 'dist'
15
+ domain = 'localhost'
16
+
17
+ in_temporary_project do
18
+ with_temp_content_directory do
19
+ page = create(:page)
20
+
21
+ Nesta::Static::Site.new(build_dir, domain).render_pages
22
+
23
+ html_file = File.join(build_dir, page.abspath + '.html')
24
+ markup = open(html_file).read
25
+
26
+ assert markup.include?("<title>#{page.title}</title>")
27
+ end
28
+ end
29
+ end
30
+
31
+ it 'renders a 404 not found page' do
32
+ build_dir = 'dist'
33
+ domain = 'localhost'
34
+
35
+ in_temporary_project do
36
+ with_temp_content_directory do
37
+ Nesta::Static::Site.new(build_dir, domain).render_not_found
38
+
39
+ html_file = File.join(build_dir, '404.html')
40
+ markup = open(html_file).read
41
+
42
+ assert markup.include?("<h1>Page not found</h1>")
43
+ end
44
+ end
45
+ end
46
+
47
+ it 'renders Atom feed' do
48
+ build_dir = 'dist'
49
+ domain = 'mysite.com'
50
+
51
+ in_temporary_project do
52
+ with_temp_content_directory do
53
+ article = create(:article)
54
+ Nesta::Static::Site.new(build_dir, domain).render_atom_feed
55
+
56
+ xml_file = File.join(build_dir, 'articles.xml')
57
+ xml = open(xml_file).read
58
+
59
+ assert xml.include?("<link href='https://#{domain + article.abspath}'")
60
+ end
61
+ end
62
+ end
63
+
64
+ it 'includes domain name in sitemap' do
65
+ build_dir = 'dist'
66
+ domain = 'mysite.com'
67
+
68
+ in_temporary_project do
69
+ with_temp_content_directory do
70
+ page = create(:page)
71
+ Nesta::Static::Site.new(build_dir, domain).render_sitemap
72
+
73
+ xml_file = File.join(build_dir, 'sitemap.xml')
74
+ xml = open(xml_file).read
75
+
76
+ assert xml.include?(domain + page.abspath)
77
+ end
78
+ end
79
+ end
80
+
81
+ it "renders the user's list of templated assets" do
82
+ build_dir = 'dist'
83
+ css_path = '/css/styles.css'
84
+ build_config = {}
85
+
86
+ in_temporary_project do
87
+ stub_config('build' => { 'templated_assets' => [css_path] }) do
88
+ views = File.join(project_root, 'views')
89
+ FileUtils.mkdir_p(views)
90
+ open(File.join(views, 'styles.sass'), 'w') do |sass|
91
+ sass.write("p\n font-size: 1em\n")
92
+ end
93
+
94
+ site = Nesta::Static::Site.new(build_dir, 'mysite.com')
95
+ site.render_templated_assets
96
+
97
+ css_file = File.join(build_dir, css_path)
98
+ assert_exists_in_project(css_file)
99
+
100
+ assert_equal open(css_file).read, "p {\n font-size: 1em;\n}"
101
+ end
102
+ end
103
+ end
104
+ end