nesta 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +21 -0
  3. data/.gitignore +1 -0
  4. data/.gitmodules +0 -6
  5. data/CHANGES +99 -0
  6. data/Gemfile.lock +43 -39
  7. data/LICENSE +1 -1
  8. data/README.md +9 -14
  9. data/RELEASING.md +9 -7
  10. data/Rakefile +2 -2
  11. data/bin/nesta +5 -2
  12. data/config/deploy.rb.sample +1 -1
  13. data/lib/nesta/app.rb +1 -2
  14. data/lib/nesta/commands/build.rb +38 -0
  15. data/lib/nesta/commands/demo/content.rb +8 -10
  16. data/lib/nesta/commands/edit.rb +2 -6
  17. data/lib/nesta/commands/new.rb +11 -12
  18. data/lib/nesta/commands/plugin/create.rb +7 -9
  19. data/lib/nesta/commands/template.rb +20 -0
  20. data/lib/nesta/commands/theme/create.rb +8 -8
  21. data/lib/nesta/commands/theme/enable.rb +3 -5
  22. data/lib/nesta/commands/theme/install.rb +6 -10
  23. data/lib/nesta/commands.rb +9 -0
  24. data/lib/nesta/config.rb +49 -75
  25. data/lib/nesta/config_file.rb +29 -0
  26. data/lib/nesta/helpers.rb +0 -5
  27. data/lib/nesta/models.rb +33 -34
  28. data/lib/nesta/navigation.rb +0 -5
  29. data/lib/nesta/overrides.rb +32 -43
  30. data/lib/nesta/plugin.rb +0 -16
  31. data/lib/nesta/static/assets.rb +50 -0
  32. data/lib/nesta/static/html_file.rb +26 -0
  33. data/lib/nesta/static/site.rb +104 -0
  34. data/lib/nesta/system_command.rb +15 -0
  35. data/lib/nesta/version.rb +1 -1
  36. data/lib/nesta.rb +7 -4
  37. data/nesta.gemspec +5 -5
  38. data/templates/config/config.yml +28 -2
  39. data/templates/themes/README.md +1 -1
  40. data/templates/themes/views/master.sass +1 -1
  41. data/test/integration/atom_feed_test.rb +1 -1
  42. data/test/integration/commands/build_test.rb +53 -0
  43. data/test/integration/commands/demo/content_test.rb +8 -6
  44. data/test/integration/commands/edit_test.rb +4 -4
  45. data/test/integration/commands/new_test.rb +22 -51
  46. data/test/integration/commands/plugin/create_test.rb +7 -4
  47. data/test/integration/commands/theme/create_test.rb +8 -2
  48. data/test/integration/commands/theme/enable_test.rb +7 -1
  49. data/test/integration/commands/theme/install_test.rb +13 -9
  50. data/test/integration/overrides_test.rb +1 -1
  51. data/test/integration/sitemap_test.rb +1 -1
  52. data/test/support/temporary_files.rb +1 -1
  53. data/test/support/test_configuration.rb +2 -4
  54. data/test/unit/config_test.rb +25 -94
  55. data/test/unit/static/assets_test.rb +56 -0
  56. data/test/unit/static/html_file_test.rb +41 -0
  57. data/test/unit/static/site_test.rb +104 -0
  58. data/test/unit/system_command_test.rb +20 -0
  59. data/views/atom.haml +2 -2
  60. data/views/comments.haml +2 -2
  61. data/views/footer.haml +1 -1
  62. data/views/header.haml +2 -3
  63. data/views/layout.haml +2 -2
  64. data/views/master.sass +1 -1
  65. data/views/mixins.sass +2 -2
  66. data/views/normalize.scss +0 -1
  67. data/views/sitemap.haml +1 -1
  68. metadata +44 -31
  69. data/.hound.yml +0 -2
  70. data/.rspec +0 -1
  71. data/.travis.yml +0 -11
  72. data/lib/nesta/commands/command.rb +0 -57
  73. data/test/support/silence_commands_during_tests.rb +0 -5
  74. data/test/unit/commands_test.rb +0 -23
@@ -0,0 +1,20 @@
1
+ module Nesta
2
+ module Commands
3
+ class Template
4
+ def initialize(filename)
5
+ @filename = filename
6
+ end
7
+
8
+ def template_path
9
+ dir = File.expand_path('../../../templates', File.dirname(__FILE__))
10
+ File.join(dir, @filename)
11
+ end
12
+
13
+ def copy_to(dest, context)
14
+ FileUtils.mkdir_p(File.dirname(dest))
15
+ template = ERB.new(File.read(template_path), trim_mode: "-")
16
+ File.open(dest, 'w') { |file| file.puts template.result(context) }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,18 +1,16 @@
1
- require File.expand_path('../command', File.dirname(__FILE__))
2
-
3
1
  module Nesta
4
2
  module Commands
5
3
  module Theme
6
4
  class Create
7
- include Command
8
-
9
5
  def initialize(*args)
10
6
  name = args.shift
11
7
  options = args.shift || {}
12
8
  name.nil? && (raise UsageError.new('name not specified'))
13
9
  @name = name
14
10
  @theme_path = Nesta::Path.themes(@name)
15
- fail("#{@theme_path} already exists") if File.exist?(@theme_path)
11
+ if File.exist?(@theme_path)
12
+ Nesta.fail_with("#{@theme_path} already exists")
13
+ end
16
14
  end
17
15
 
18
16
  def make_directories
@@ -20,15 +18,17 @@ module Nesta
20
18
  FileUtils.mkdir_p(File.join(@theme_path, 'views'))
21
19
  end
22
20
 
23
- def execute
21
+ def execute(process)
24
22
  make_directories
25
- copy_templates(
23
+ {
26
24
  'themes/README.md' => "#{@theme_path}/README.md",
27
25
  'themes/app.rb' => "#{@theme_path}/app.rb",
28
26
  'themes/views/layout.haml' => "#{@theme_path}/views/layout.haml",
29
27
  'themes/views/page.haml' => "#{@theme_path}/views/page.haml",
30
28
  'themes/views/master.sass' => "#{@theme_path}/views/master.sass"
31
- )
29
+ }.each do |src, dest|
30
+ Nesta::Commands::Template.new(src).copy_to(dest, binding)
31
+ end
32
32
  end
33
33
  end
34
34
  end
@@ -1,11 +1,9 @@
1
- require File.expand_path('../command', File.dirname(__FILE__))
1
+ require File.expand_path('../../config_file', File.dirname(__FILE__))
2
2
 
3
3
  module Nesta
4
4
  module Commands
5
5
  module Theme
6
6
  class Enable
7
- include Command
8
-
9
7
  def initialize(*args)
10
8
  name = args.shift
11
9
  options = args.shift || {}
@@ -13,8 +11,8 @@ module Nesta
13
11
  @name = name
14
12
  end
15
13
 
16
- def execute
17
- update_config_yaml(/^\s*#?\s*theme:.*/, "theme: #{@name}")
14
+ def execute(process)
15
+ Nesta::ConfigFile.new.set_value('theme', @name)
18
16
  end
19
17
  end
20
18
  end
@@ -1,11 +1,7 @@
1
- require File.expand_path('../command', File.dirname(__FILE__))
2
-
3
1
  module Nesta
4
2
  module Commands
5
3
  module Theme
6
4
  class Install
7
- include Command
8
-
9
5
  def initialize(*args)
10
6
  @url = args.shift
11
7
  @url.nil? && (raise UsageError.new('URL not specified'))
@@ -16,14 +12,14 @@ module Nesta
16
12
  File.basename(@url, '.git').sub(/nesta-theme-/, '')
17
13
  end
18
14
 
19
- def execute
20
- run_process('git', 'clone', @url, "themes/#{theme_name}")
21
- FileUtils.rm_r(File.join("themes/#{theme_name}", '.git'))
22
- enable
15
+ def execute(process)
16
+ process.run('git', 'clone', @url, "themes/#{theme_name}")
17
+ FileUtils.rm_rf(File.join("themes/#{theme_name}", '.git'))
18
+ enable(process)
23
19
  end
24
20
 
25
- def enable
26
- Enable.new(theme_name).execute
21
+ def enable(process)
22
+ Enable.new(theme_name).execute(process)
27
23
  end
28
24
  end
29
25
  end
@@ -4,10 +4,19 @@ require 'fileutils'
4
4
  require File.expand_path('env', File.dirname(__FILE__))
5
5
  require File.expand_path('app', File.dirname(__FILE__))
6
6
  require File.expand_path('path', File.dirname(__FILE__))
7
+ require File.expand_path('system_command', File.dirname(__FILE__))
7
8
  require File.expand_path('version', File.dirname(__FILE__))
8
9
 
10
+ require File.expand_path('commands/build', File.dirname(__FILE__))
9
11
  require File.expand_path('commands/demo', File.dirname(__FILE__))
10
12
  require File.expand_path('commands/edit', File.dirname(__FILE__))
11
13
  require File.expand_path('commands/new', File.dirname(__FILE__))
12
14
  require File.expand_path('commands/plugin', File.dirname(__FILE__))
15
+ require File.expand_path('commands/template', File.dirname(__FILE__))
13
16
  require File.expand_path('commands/theme', File.dirname(__FILE__))
17
+
18
+ module Nesta
19
+ module Commands
20
+ class UsageError < RuntimeError; end
21
+ end
22
+ end
data/lib/nesta/config.rb CHANGED
@@ -1,115 +1,89 @@
1
+ require 'singleton'
1
2
  require 'yaml'
2
3
 
4
+ require_relative './config_file'
5
+
3
6
  module Nesta
4
7
  class Config
8
+ include Singleton
9
+
5
10
  class NotDefined < KeyError; end
6
11
 
7
- @settings = %w[
8
- cache
12
+ SETTINGS = %w[
13
+ author
14
+ build
9
15
  content
10
16
  disqus_short_name
17
+ domain
11
18
  google_analytics_code
12
19
  read_more
13
20
  subtitle
14
21
  theme
15
22
  title
16
23
  ]
17
- @author_settings = %w[name uri email]
18
- @yaml = nil
19
-
24
+
20
25
  class << self
21
- attr_accessor :settings, :author_settings, :yaml_conf
26
+ extend Forwardable
27
+ def_delegators *[:instance, :fetch].concat(SETTINGS.map(&:to_sym))
22
28
  end
23
29
 
24
- def self.fetch(key, *default)
25
- from_environment(key.to_s)
30
+ attr_accessor :config
31
+
32
+ def fetch(setting, *default)
33
+ setting = setting.to_s
34
+ self.config ||= read_config_file(setting)
35
+ env_config = config.fetch(Nesta::App.environment.to_s, {})
36
+ env_config.fetch(
37
+ setting,
38
+ config.fetch(setting) { raise NotDefined.new(setting) }
39
+ )
26
40
  rescue NotDefined
27
- begin
28
- from_yaml(key.to_s)
29
- rescue NotDefined
30
- default.empty? && raise || (return default.first)
31
- end
41
+ default.empty? && raise || (return default.first)
32
42
  end
33
43
 
34
- def self.method_missing(method, *args)
35
- if settings.include?(method.to_s)
36
- fetch(method, nil)
44
+ def method_missing(method, *args)
45
+ if SETTINGS.include?(method.to_s)
46
+ fetch(method.to_s, nil)
37
47
  else
38
48
  super
39
49
  end
40
50
  end
41
-
42
- def self.author
43
- environment_config = {}
44
- %w[name uri email].each do |setting|
45
- variable = "NESTA_AUTHOR__#{setting.upcase}"
46
- ENV[variable] && environment_config[setting] = ENV[variable]
47
- end
48
- environment_config.empty? ? from_yaml('author') : environment_config
49
- rescue NotDefined
50
- nil
51
- end
52
51
 
53
- def self.cache
54
- Nesta.deprecated('Nesta::Config.cache',
55
- 'see http://nestacms.com/docs/deployment/page-caching')
56
- end
57
-
58
- def self.content_path(basename = nil)
59
- get_path(content, basename)
60
- end
61
-
62
- def self.page_path(basename = nil)
63
- get_path(File.join(content_path, "pages"), basename)
52
+ def respond_to_missing?(method, include_private = false)
53
+ SETTINGS.include?(method.to_s) || super
64
54
  end
65
-
66
- def self.attachment_path(basename = nil)
67
- get_path(File.join(content_path, "attachments"), basename)
68
- end
69
-
70
- def self.yaml_path
71
- File.expand_path('config/config.yml', Nesta::App.root)
55
+
56
+ def build
57
+ fetch('build', {})
72
58
  end
73
59
 
74
- def self.read_more
60
+ def read_more
75
61
  fetch('read_more', 'Continue reading')
76
62
  end
77
63
 
78
- def self.from_environment(setting)
79
- value = ENV.fetch("NESTA_#{setting.upcase}")
80
- rescue KeyError
64
+ private
65
+
66
+ def read_config_file(setting)
67
+ YAML::load(ERB.new(IO.read(Nesta::ConfigFile.path)).result)
68
+ rescue Errno::ENOENT
81
69
  raise NotDefined.new(setting)
82
- else
83
- overrides = { "true" => true, "false" => false }
84
- overrides.has_key?(value) ? overrides[value] : value
85
- end
86
- private_class_method :from_environment
87
-
88
- def self.yaml_exists?
89
- File.exist?(yaml_path)
90
70
  end
91
- private_class_method :yaml_exists?
92
71
 
93
- def self.from_hash(hash, setting)
94
- hash.fetch(setting) { raise NotDefined.new(setting) }
95
- end
96
- private_class_method :from_hash
97
-
98
- def self.from_yaml(setting)
99
- raise NotDefined.new(setting) unless yaml_exists?
100
- self.yaml_conf ||= YAML::load(ERB.new(IO.read(yaml_path)).result)
101
- env_config = self.yaml_conf.fetch(Nesta::App.environment.to_s, {})
102
- begin
103
- from_hash(env_config, setting)
104
- rescue NotDefined
105
- from_hash(self.yaml_conf, setting)
106
- end
107
- end
108
- private_class_method :from_yaml
109
-
110
72
  def self.get_path(dirname, basename)
111
73
  basename.nil? ? dirname : File.join(dirname, basename)
112
74
  end
113
75
  private_class_method :get_path
76
+
77
+ def self.content_path(basename = nil)
78
+ get_path(content, basename)
79
+ end
80
+
81
+ def self.page_path(basename = nil)
82
+ get_path(File.join(content_path, "pages"), basename)
83
+ end
84
+
85
+ def self.attachment_path(basename = nil)
86
+ get_path(File.join(content_path, "attachments"), basename)
87
+ end
114
88
  end
115
89
  end
@@ -0,0 +1,29 @@
1
+ module Nesta
2
+ class ConfigFile
3
+ def self.path
4
+ File.expand_path('config/config.yml', Nesta::App.root)
5
+ end
6
+
7
+ def set_value(key, value)
8
+ pattern = /^\s*#?\s*#{key}:.*/
9
+ replacement = "#{key}: #{value}"
10
+
11
+ configured = false
12
+ File.open(self.class.path, 'r+') do |file|
13
+ output = ''
14
+ file.each_line do |line|
15
+ if configured
16
+ output << line
17
+ else
18
+ output << line.sub(pattern, replacement)
19
+ configured = true if line =~ pattern
20
+ end
21
+ end
22
+ output << "#{replacement}\n" unless configured
23
+ file.pos = 0
24
+ file.print(output)
25
+ file.truncate(file.pos)
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/nesta/helpers.rb CHANGED
@@ -60,11 +60,6 @@ module Nesta
60
60
  date.strftime("%d %B %Y")
61
61
  end
62
62
 
63
- def local_stylesheet?
64
- Nesta.deprecated('local_stylesheet?', 'use local_stylesheet_link_tag')
65
- File.exist?(File.expand_path('views/local.sass', Nesta::App.root))
66
- end
67
-
68
63
  def local_stylesheet_link_tag(name)
69
64
  pattern = File.expand_path("views/#{name}.s{a,c}ss", Nesta::App.root)
70
65
  if Dir.glob(pattern).size > 0
data/lib/nesta/models.rb CHANGED
@@ -380,45 +380,44 @@ module Nesta
380
380
  end
381
381
  end
382
382
 
383
- private
384
- def self.append_menu_item(menu, file, depth)
385
- path = file.readline
386
- rescue EOFError
387
- else
388
- page = Page.load(path.strip)
389
- current_depth = path.scan(INDENT).size
390
- if page
391
- if current_depth > depth
392
- sub_menu_for_depth(menu, depth) << [page]
393
- else
394
- sub_menu_for_depth(menu, current_depth) << page
395
- end
383
+ private_class_method def self.append_menu_item(menu, file, depth)
384
+ path = file.readline
385
+ rescue EOFError
386
+ else
387
+ page = Page.load(path.strip)
388
+ current_depth = path.scan(INDENT).size
389
+ if page
390
+ if current_depth > depth
391
+ sub_menu_for_depth(menu, depth) << [page]
392
+ else
393
+ sub_menu_for_depth(menu, current_depth) << page
396
394
  end
397
- append_menu_item(menu, file, current_depth)
398
395
  end
396
+ append_menu_item(menu, file, current_depth)
397
+ end
399
398
 
400
- def self.sub_menu_for_depth(menu, depth)
401
- sub_menu = menu
402
- depth.times { sub_menu = sub_menu[-1] }
403
- sub_menu
404
- end
399
+ private_class_method def self.sub_menu_for_depth(menu, depth)
400
+ sub_menu = menu
401
+ depth.times { sub_menu = sub_menu[-1] }
402
+ sub_menu
403
+ end
405
404
 
406
- def self.find_menu_item_by_path(menu, path)
407
- item = menu.detect do |item|
408
- item.respond_to?(:path) && (item.path == path)
409
- end
410
- if item
411
- subsequent = menu[menu.index(item) + 1]
412
- item = [item]
413
- item << subsequent if subsequent.respond_to?(:each)
414
- else
415
- sub_menus = menu.select { |menu_item| menu_item.respond_to?(:each) }
416
- sub_menus.each do |sub_menu|
417
- item = find_menu_item_by_path(sub_menu, path)
418
- break if item
419
- end
405
+ private_class_method def self.find_menu_item_by_path(menu, path)
406
+ item = menu.detect do |item|
407
+ item.respond_to?(:path) && (item.path == path)
408
+ end
409
+ if item
410
+ subsequent = menu[menu.index(item) + 1]
411
+ item = [item]
412
+ item << subsequent if subsequent.respond_to?(:each)
413
+ else
414
+ sub_menus = menu.select { |menu_item| menu_item.respond_to?(:each) }
415
+ sub_menus.each do |sub_menu|
416
+ item = find_menu_item_by_path(sub_menu, path)
417
+ break if item
420
418
  end
421
- item
422
419
  end
420
+ item
421
+ end
423
422
  end
424
423
  end
@@ -64,11 +64,6 @@ module Nesta
64
64
  raise
65
65
  end
66
66
 
67
- def breadcrumb_label(page)
68
- Nesta.deprecated('breadcrumb_label', 'use link_text')
69
- link_text(page)
70
- end
71
-
72
67
  def current_item?(item)
73
68
  request.path_info == item.abspath
74
69
  end
@@ -1,30 +1,47 @@
1
1
  module Nesta
2
2
  module Overrides
3
3
  module Renderers
4
- def haml(template, options = {}, locals = {})
5
- defaults, engine = Overrides.render_options(template, :haml)
6
- super(template, defaults.merge(options), locals)
7
- end
8
-
9
- def erb(template, options = {}, locals = {})
10
- defaults, engine = Overrides.render_options(template, :erb)
11
- super(template, defaults.merge(options), locals)
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
- defaults, engine = Overrides.render_options(template, :scss)
16
- super(template, defaults.merge(options), locals)
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
- defaults, engine = Overrides.render_options(template, :sass)
21
- super(template, defaults.merge(options), locals)
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
- defaults, engine = Overrides.render_options(template, :sass, :scss)
26
- renderer = Sinatra::Templates.instance_method(engine)
27
- renderer.bind(self).call(template, defaults.merge(options), locals)
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