nesta 0.11.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/tests.yml +21 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGES +44 -2
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +73 -55
  7. data/LICENSE +1 -1
  8. data/README.md +7 -14
  9. data/RELEASING.md +10 -9
  10. data/Rakefile +20 -3
  11. data/bin/nesta +1 -1
  12. data/config/deploy.rb.sample +1 -1
  13. data/lib/nesta/app.rb +4 -8
  14. data/lib/nesta/commands/demo/content.rb +28 -12
  15. data/lib/nesta/commands/edit.rb +2 -6
  16. data/lib/nesta/commands/new.rb +9 -11
  17. data/lib/nesta/commands/plugin/create.rb +7 -9
  18. data/lib/nesta/commands/template.rb +20 -0
  19. data/lib/nesta/commands/theme/create.rb +8 -8
  20. data/lib/nesta/commands/theme/enable.rb +3 -5
  21. data/lib/nesta/commands/theme/install.rb +12 -14
  22. data/lib/nesta/commands.rb +8 -0
  23. data/lib/nesta/config_file.rb +25 -0
  24. data/lib/nesta/helpers.rb +14 -0
  25. data/lib/nesta/models.rb +26 -22
  26. data/lib/nesta/navigation.rb +1 -1
  27. data/lib/nesta/system_command.rb +15 -0
  28. data/lib/nesta/version.rb +1 -1
  29. data/lib/nesta.rb +6 -1
  30. data/nesta.gemspec +11 -12
  31. data/templates/config/config.yml +1 -1
  32. data/{spec → test}/fixtures/nesta-plugin-test/Gemfile +0 -0
  33. data/{spec → test}/fixtures/nesta-plugin-test/Rakefile +0 -0
  34. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/init.rb +0 -0
  35. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/version.rb +0 -0
  36. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test.rb +0 -0
  37. data/{spec → test}/fixtures/nesta-plugin-test/nesta-plugin-test.gemspec +0 -0
  38. data/test/integration/atom_feed_test.rb +178 -0
  39. data/test/integration/commands/demo/content_test.rb +33 -0
  40. data/test/integration/commands/edit_test.rb +21 -0
  41. data/test/integration/commands/new_test.rb +91 -0
  42. data/test/integration/commands/plugin/create_test.rb +131 -0
  43. data/test/integration/commands/theme/create_test.rb +41 -0
  44. data/test/integration/commands/theme/enable_test.rb +28 -0
  45. data/test/integration/commands/theme/install_test.rb +66 -0
  46. data/test/integration/default_theme_test.rb +220 -0
  47. data/test/integration/overrides_test.rb +118 -0
  48. data/test/integration/route_handlers_test.rb +96 -0
  49. data/test/integration/sitemap_test.rb +85 -0
  50. data/test/integration_test_helper.rb +61 -0
  51. data/test/support/model_factory.rb +169 -0
  52. data/test/support/temporary_files.rb +33 -0
  53. data/test/support/test_configuration.rb +19 -0
  54. data/test/test_helper.rb +26 -0
  55. data/test/unit/config_test.rb +138 -0
  56. data/test/unit/file_model_test.rb +71 -0
  57. data/test/unit/menu_test.rb +82 -0
  58. data/test/unit/page_test.rb +571 -0
  59. data/test/unit/path_test.rb +41 -0
  60. data/test/unit/plugin_test.rb +47 -0
  61. data/test/unit/system_command_test.rb +20 -0
  62. data/views/master.sass +1 -1
  63. metadata +90 -89
  64. data/.hound.yml +0 -2
  65. data/.rspec +0 -1
  66. data/.travis.yml +0 -6
  67. data/lib/nesta/commands/command.rb +0 -58
  68. data/smoke-test.sh +0 -107
  69. data/spec/atom_spec.rb +0 -141
  70. data/spec/commands/demo/content_spec.rb +0 -65
  71. data/spec/commands/edit_spec.rb +0 -27
  72. data/spec/commands/new_spec.rb +0 -88
  73. data/spec/commands/plugin/create_spec.rb +0 -97
  74. data/spec/commands/system_spec.rb +0 -25
  75. data/spec/commands/theme/create_spec.rb +0 -41
  76. data/spec/commands/theme/enable_spec.rb +0 -44
  77. data/spec/commands/theme/install_spec.rb +0 -56
  78. data/spec/config_spec.rb +0 -127
  79. data/spec/model_factory.rb +0 -92
  80. data/spec/models_spec.rb +0 -700
  81. data/spec/overrides_spec.rb +0 -132
  82. data/spec/page_spec.rb +0 -560
  83. data/spec/path_spec.rb +0 -28
  84. data/spec/plugin_spec.rb +0 -51
  85. data/spec/sitemap_spec.rb +0 -105
  86. data/spec/spec_helper.rb +0 -114
@@ -1,65 +0,0 @@
1
- require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:demo:content" do
5
- include_context "temporary working directory"
6
-
7
- before(:each) do
8
- @config_path = project_path('config/config.yml')
9
- FileUtils.mkdir_p(File.dirname(@config_path))
10
- Nesta::Config.stub(:yaml_path).and_return(@config_path)
11
- create_config_yaml('content: path/to/content')
12
- Nesta::App.stub(:root).and_return(@project_path)
13
- @repo_url = 'git://github.com/gma/nesta-demo-content.git'
14
- @demo_path = project_path('content-demo')
15
- @command = Nesta::Commands::Demo::Content.new
16
- @command.stub(:run_process)
17
- end
18
-
19
- it "should clone the repository" do
20
- @command.should_receive(:run_process).with(
21
- 'git', 'clone', @repo_url, @demo_path)
22
- @command.execute
23
- end
24
-
25
- it "should configure the content directory" do
26
- @command.execute
27
- File.read(@config_path).should match(/^content: content-demo/)
28
- end
29
-
30
- describe "when repository already exists" do
31
- before(:each) do
32
- FileUtils.mkdir_p(@demo_path)
33
- end
34
-
35
- it "should update the repository" do
36
- @command.should_receive(:run_process).with(
37
- 'git', 'pull', 'origin', 'master')
38
- @command.execute
39
- end
40
- end
41
-
42
- describe "when site versioned with git" do
43
- before(:each) do
44
- @exclude_path = project_path('.git/info/exclude')
45
- FileUtils.mkdir_p(File.dirname(@exclude_path))
46
- File.open(@exclude_path, 'w') { |file| file.puts '# Excludes' }
47
- end
48
-
49
- it "should tell git to ignore content-demo" do
50
- @command.execute
51
- File.read(@exclude_path).should match(/content-demo/)
52
- end
53
-
54
- describe "and content-demo already ignored" do
55
- before(:each) do
56
- File.open(@exclude_path, 'w') { |file| file.puts 'content-demo' }
57
- end
58
-
59
- it "shouldn't tell git to ignore it twice" do
60
- @command.execute
61
- File.read(@exclude_path).scan('content-demo').size.should == 1
62
- end
63
- end
64
- end
65
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:edit" do
5
- include_context "temporary working directory"
6
-
7
- before(:each) do
8
- Nesta::Config.stub(:content_path).and_return('content')
9
- @page_path = 'path/to/page.mdown'
10
- @command = Nesta::Commands::Edit.new(@page_path)
11
- @command.stub(:run_process)
12
- end
13
-
14
- it "should launch the editor" do
15
- ENV['EDITOR'] = 'vi'
16
- full_path = File.join('content/pages', @page_path)
17
- @command.should_receive(:run_process).with(ENV['EDITOR'], full_path)
18
- @command.execute
19
- end
20
-
21
- it "should not try and launch an editor if environment not setup" do
22
- ENV.delete('EDITOR')
23
- @command.should_not_receive(:run_process)
24
- $stderr.stub(:puts)
25
- @command.execute
26
- end
27
- end
@@ -1,88 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:new" do
5
- include_context "temporary working directory"
6
-
7
- def gemfile_source
8
- File.read(project_path('Gemfile'))
9
- end
10
-
11
- def rakefile_source
12
- File.read(project_path('Rakefile'))
13
- end
14
-
15
- describe "without options" do
16
- before(:each) do
17
- Nesta::Commands::New.new(@project_path).execute
18
- end
19
-
20
- it "should create the content directories" do
21
- should_exist('content/attachments')
22
- should_exist('content/pages')
23
- end
24
-
25
- it "should create the home page" do
26
- should_exist('content/pages/index.haml')
27
- end
28
-
29
- it "should create the rackup file" do
30
- should_exist('config.ru')
31
- end
32
-
33
- it "should create the config.yml file" do
34
- should_exist('config/config.yml')
35
- end
36
-
37
- it "should add a Gemfile" do
38
- should_exist('Gemfile')
39
- gemfile_source.should match(/gem 'nesta'/)
40
- end
41
- end
42
-
43
- describe "--git" do
44
- before(:each) do
45
- @command = Nesta::Commands::New.new(@project_path, 'git' => '')
46
- @command.stub(:run_process)
47
- end
48
-
49
- it "should create a .gitignore file" do
50
- @command.execute
51
- File.read(project_path('.gitignore')).should match(/\.bundle/)
52
- end
53
-
54
- it "should create a git repo" do
55
- @command.should_receive(:run_process).with('git', 'init')
56
- @command.execute
57
- end
58
-
59
- it "should commit the blank project" do
60
- @command.should_receive(:run_process).with('git', 'add', '.')
61
- @command.should_receive(:run_process).with(
62
- 'git', 'commit', '-m', 'Initial commit')
63
- @command.execute
64
- end
65
- end
66
-
67
- describe "--vlad" do
68
- before(:each) do
69
- Nesta::Commands::New.new(@project_path, 'vlad' => '').execute
70
- end
71
-
72
- it "should add vlad to Gemfile" do
73
- gemfile_source.should match(/gem 'vlad', '2.1.0'/)
74
- gemfile_source.should match(/gem 'vlad-git', '2.2.0'/)
75
- end
76
-
77
- it "should configure the vlad rake tasks" do
78
- should_exist('Rakefile')
79
- rakefile_source.should match(/require 'vlad'/)
80
- end
81
-
82
- it "should create deploy.rb" do
83
- should_exist('config/deploy.rb')
84
- deploy_source = File.read(project_path('config/deploy.rb'))
85
- deploy_source.should match(/set :application, 'mysite.com'/)
86
- end
87
- end
88
- end
@@ -1,97 +0,0 @@
1
- require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe 'nesta:plugin:create' do
5
- include_context 'temporary working directory'
6
-
7
- def path_in_gem(path)
8
- File.join(@gem_name, path)
9
- end
10
-
11
- def should_exist(path)
12
- File.exist?(path_in_gem(path)).should be_true
13
- end
14
-
15
- def should_contain(path, pattern)
16
- contents = File.read(path_in_gem(path))
17
- contents.should match(pattern)
18
- end
19
-
20
- before(:each) do
21
- @name = 'my-feature'
22
- @gem_name = "nesta-plugin-#{@name}"
23
- @plugins_path = temp_path('plugins')
24
- @working_dir = Dir.pwd
25
- Dir.mkdir(@plugins_path)
26
- Dir.chdir(@plugins_path)
27
- Nesta::Commands::Plugin::Create.any_instance.stub(:system)
28
- Nesta::Commands::Plugin::Create.new(@name).execute
29
- end
30
-
31
- after(:each) do
32
- Dir.chdir(@working_dir)
33
- FileUtils.rm_r(@plugins_path)
34
- end
35
-
36
- it "creates the gem's directory" do
37
- File.directory?(@gem_name).should be_true
38
- end
39
-
40
- it 'creates a README.md file with installation instructions' do
41
- should_exist('README.md')
42
- should_contain('README.md', %r{echo 'gem "#{@gem_name}"' >> Gemfile})
43
- end
44
-
45
- it 'creates .gitignore' do
46
- should_exist('.gitignore')
47
- end
48
-
49
- it 'creates the gemspec' do
50
- path = "#{@gem_name}.gemspec"
51
- should_exist(path)
52
- should_contain(path, %r{require "#{@gem_name}/version"})
53
- should_contain(path, %r{Nesta::Plugin::My::Feature::VERSION})
54
- end
55
-
56
- it 'creates a Gemfile' do
57
- should_exist('Gemfile')
58
- end
59
-
60
- it 'creates Rakefile that helps with packaging the gem' do
61
- should_exist("Rakefile")
62
- end
63
-
64
- it 'creates default folder for Ruby files' do
65
- code_directory = File.join(@gem_name, 'lib', @gem_name)
66
- File.directory?(code_directory).should be_true
67
- end
68
-
69
- it 'creates file required when gem loaded' do
70
- path = "#{File.join('lib', @gem_name)}.rb"
71
- should_exist(path)
72
- should_contain(path, %r{require "#{@gem_name}/version"})
73
- end
74
-
75
- it 'creates version.rb' do
76
- path = File.join('lib', @gem_name, 'version.rb')
77
- should_exist(path)
78
- should_contain path, <<-EOF
79
- module Nesta
80
- module Plugin
81
- module My
82
- module Feature
83
- VERSION = '0.1.0'
84
- end
85
- end
86
- end
87
- end
88
- EOF
89
- end
90
-
91
- it 'creates skeleton code for the plugin in init.rb' do
92
- path = File.join('lib', @gem_name, 'init.rb')
93
- should_exist(path)
94
- should_contain(path, "module Nesta\n module Plugin\n module My::Feature")
95
- should_contain(path, 'helpers Nesta::Plugin::My::Feature::Helpers')
96
- end
97
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- class TestCommand
5
- include Nesta::Commands::Command
6
- end
7
-
8
- describe "Nesta::Commands::Command.run_process" do
9
- before do
10
- @stderr = $stderr
11
- $stderr = File.new('/dev/null', 'w')
12
- end
13
-
14
- after do
15
- $stderr.close
16
- $stderr = @stderr
17
- end
18
-
19
- it 'can run an external process and catch errors' do
20
- TestCommand.new.run_process('ls / >/dev/null')
21
- expect {
22
- TestCommand.new.run_process('ls /no-such-file 2>/dev/null')
23
- }.to raise_error(SystemExit)
24
- end
25
- end
@@ -1,41 +0,0 @@
1
- require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:theme:create" do
5
- include_context "temporary working directory"
6
-
7
- def should_exist(file)
8
- File.exist?(Nesta::Path.themes(@name, file)).should be_true
9
- end
10
-
11
- before(:each) do
12
- Nesta::App.stub(:root).and_return(TempFileHelper::TEMP_DIR)
13
- @name = 'my-new-theme'
14
- Nesta::Commands::Theme::Create.new(@name).execute
15
- end
16
-
17
- it "should create the theme directory" do
18
- File.directory?(Nesta::Path.themes(@name)).should be_true
19
- end
20
-
21
- it "should create a dummy README file" do
22
- should_exist('README.md')
23
- text = File.read(Nesta::Path.themes(@name, 'README.md'))
24
- text.should match(/#{@name} is a theme/)
25
- end
26
-
27
- it "should create a default app.rb file" do
28
- should_exist('app.rb')
29
- end
30
-
31
- it "should create public and views directories" do
32
- should_exist("public/#{@name}")
33
- should_exist('views')
34
- end
35
-
36
- it "should copy the default view templates into views" do
37
- %w(layout.haml page.haml master.sass).each do |file|
38
- should_exist("views/#{file}")
39
- end
40
- end
41
- end
@@ -1,44 +0,0 @@
1
- require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:theme:enable" do
5
- include_context "temporary working directory"
6
-
7
- before(:each) do
8
- config = temp_path('config.yml')
9
- Nesta::Config.stub(:yaml_path).and_return(config)
10
- @name = 'mytheme'
11
- @command = Nesta::Commands::Theme::Enable.new(@name)
12
- end
13
-
14
- shared_examples_for "command that configures the theme" do
15
- it "should enable the theme" do
16
- @command.execute
17
- File.read(Nesta::Config.yaml_path).should match(/^theme: #{@name}/)
18
- end
19
- end
20
-
21
- describe "when theme config is commented out" do
22
- before(:each) do
23
- create_config_yaml(' # theme: blah')
24
- end
25
-
26
- it_should_behave_like "command that configures the theme"
27
- end
28
-
29
- describe "when another theme is configured" do
30
- before(:each) do
31
- create_config_yaml('theme: another')
32
- end
33
-
34
- it_should_behave_like "command that configures the theme"
35
- end
36
-
37
- describe "when no theme config exists" do
38
- before(:each) do
39
- create_config_yaml('# I have no theme config')
40
- end
41
-
42
- it_should_behave_like "command that configures the theme"
43
- end
44
- end
@@ -1,56 +0,0 @@
1
- require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('../../../lib/nesta/commands', File.dirname(__FILE__))
3
-
4
- describe "nesta:theme:install" do
5
- include_context "temporary working directory"
6
-
7
- before(:each) do
8
- @repo_url = 'git://github.com/gma/nesta-theme-mine.git'
9
- @theme_dir = 'themes/mine'
10
- FileUtils.mkdir_p(File.join(@theme_dir, '.git'))
11
- @command = Nesta::Commands::Theme::Install.new(@repo_url)
12
- @command.stub(:enable)
13
- @command.stub(:run_process)
14
- end
15
-
16
- after(:each) do
17
- FileUtils.rm_r(@theme_dir)
18
- end
19
-
20
- it "should clone the repository" do
21
- @command.should_receive(:run_process).with(
22
- 'git', 'clone', @repo_url, @theme_dir)
23
- @command.execute
24
- end
25
-
26
- it "should remove the theme's .git directory" do
27
- @command.execute
28
- File.exist?(@theme_dir).should be_true
29
- File.exist?(File.join(@theme_dir, '.git')).should be_false
30
- end
31
-
32
- it "should enable the freshly installed theme" do
33
- @command.should_receive(:enable)
34
- @command.execute
35
- end
36
-
37
- describe "when theme URL doesn't match recommended pattern" do
38
- before(:each) do
39
- @repo_url = 'git://foobar.com/path/to/mytheme.git'
40
- @other_theme_dir = 'themes/mytheme'
41
- FileUtils.mkdir_p(File.join(@other_theme_dir, '.git'))
42
- @command = Nesta::Commands::Theme::Install.new(@repo_url)
43
- @command.stub(:enable)
44
- end
45
-
46
- after(:each) do
47
- FileUtils.rm_r(@other_theme_dir)
48
- end
49
-
50
- it "should use the basename as theme dir" do
51
- @command.should_receive(:run_process).with(
52
- 'git', 'clone', @repo_url, @other_theme_dir)
53
- @command.execute
54
- end
55
- end
56
- end
data/spec/config_spec.rb DELETED
@@ -1,127 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- describe "Config" do
4
- after(:each) do
5
- ENV.keys.each { |variable| ENV.delete(variable) if variable =~ /NESTA_/ }
6
- end
7
-
8
- it 'should return default value for "Read more"' do
9
- Nesta::Config.read_more.should == 'Continue reading'
10
- end
11
-
12
- it 'should return nil for author when not defined' do
13
- Nesta::Config.author.should == nil
14
- end
15
-
16
- describe "when settings defined in ENV" do
17
- before(:each) do
18
- @title = "Title from ENV"
19
- ENV["NESTA_TITLE"] = @title
20
- end
21
-
22
- it "should fallback to config.yml" do
23
- stub_config_key("subtitle", "Subtitle in YAML file")
24
- Nesta::Config.subtitle.should == "Subtitle in YAML file"
25
- end
26
-
27
- it "should override config.yml" do
28
- stub_config_key("title", "Title in YAML file")
29
- Nesta::Config.title.should == @title
30
- end
31
-
32
- it "should know how to cope with boolean values" do
33
- Nesta::Config.settings << 'a_boolean'
34
- begin
35
- ENV["NESTA_A_BOOLEAN"] = "true"
36
- Nesta::Config.a_boolean.should be_true
37
- ENV["NESTA_A_BOOLEAN"] = "false"
38
- Nesta::Config.a_boolean.should be_false
39
- ensure
40
- Nesta::Config.settings.pop
41
- ENV.delete('NESTA_A_BOOLEAN')
42
- end
43
- end
44
-
45
- it 'should return configured value for "Read more"' do
46
- ENV['NESTA_READ_MORE'] = 'Read on'
47
- begin
48
- Nesta::Config.read_more.should == 'Read on'
49
- ensure
50
- ENV.delete('NESTA_READ_MORE')
51
- end
52
- end
53
-
54
- it "should set author hash from ENV" do
55
- name = "Name from ENV"
56
- uri = "URI from ENV"
57
- ENV["NESTA_AUTHOR__NAME"] = name
58
- ENV["NESTA_AUTHOR__URI"] = uri
59
- Nesta::Config.author["name"].should == name
60
- Nesta::Config.author["uri"].should == uri
61
- Nesta::Config.author["email"].should be_nil
62
- end
63
- end
64
-
65
- describe "when settings only defined in config.yml" do
66
- before(:each) do
67
- @title = "Title in YAML file"
68
- stub_config_key("subtitle", @title)
69
- end
70
-
71
- it "should read configuration from YAML" do
72
- Nesta::Config.subtitle.should == @title
73
- end
74
-
75
- it "should set author hash from YAML" do
76
- name = "Name from YAML"
77
- uri = "URI from YAML"
78
- stub_config_key("author", { "name" => name, "uri" => uri })
79
- Nesta::Config.author["name"].should == name
80
- Nesta::Config.author["uri"].should == uri
81
- Nesta::Config.author["email"].should be_nil
82
- end
83
-
84
- it "should override top level settings with environment specific settings" do
85
- stub_config_key('content', 'general/path')
86
- stub_config_key('content', 'rack_env/path', for_environment: true)
87
- Nesta::Config.content.should == 'rack_env/path'
88
- end
89
- end
90
-
91
- describe 'Nesta::Config.fetch' do
92
- it 'should be retrieve settings from environment' do
93
- ENV['NESTA_MY_SETTING'] = 'value in ENV'
94
- begin
95
- Nesta::Config.fetch('my_setting').should == 'value in ENV'
96
- Nesta::Config.fetch(:my_setting).should == 'value in ENV'
97
- ensure
98
- ENV.delete('NESTA_MY_SETTING')
99
- end
100
- end
101
-
102
- it 'should retrieved settings from YAML' do
103
- stub_config_key('my_setting', 'value in YAML')
104
- Nesta::Config.fetch('my_setting').should == 'value in YAML'
105
- Nesta::Config.fetch(:my_setting).should == 'value in YAML'
106
- end
107
-
108
- it "should throw NotDefined if a setting isn't defined" do
109
- lambda {
110
- Nesta::Config.fetch('no such setting')
111
- }.should raise_error(Nesta::Config::NotDefined)
112
- end
113
-
114
- it 'should allow default values to be set' do
115
- Nesta::Config.fetch('no such setting', 'default').should == 'default'
116
- end
117
-
118
- it 'should cope with non-truthy boolean values' do
119
- ENV['NESTA_SETTING'] = 'false'
120
- begin
121
- Nesta::Config.fetch('setting').should == false
122
- ensure
123
- ENV.delete('NESTA_SETTING')
124
- end
125
- end
126
- end
127
- end
@@ -1,92 +0,0 @@
1
- module ModelFactory
2
- def create_page(options)
3
- extension = options[:ext] || :mdown
4
- path = filename(Nesta::Config.page_path, options[:path], extension)
5
- create_file(path, options)
6
- yield(path) if block_given?
7
- Nesta::Page.new(path)
8
- end
9
-
10
- def create_article(options = {}, &block)
11
- o = {
12
- path: 'article-prefix/my-article',
13
- heading: 'My article',
14
- content: 'Content goes here',
15
- metadata: {
16
- 'date' => '29 December 2008'
17
- }.merge(options.delete(:metadata) || {})
18
- }.merge(options)
19
- create_page(o, &block)
20
- end
21
-
22
- def create_category(options = {}, &block)
23
- o = {
24
- path: 'category-prefix/my-category',
25
- heading: 'My category',
26
- content: 'Content goes here'
27
- }.merge(options)
28
- create_page(o, &block)
29
- end
30
-
31
- def write_menu_item(indent, file, menu_item)
32
- if menu_item.is_a?(Array)
33
- indent.sub!(/^/, ' ')
34
- menu_item.each { |path| write_menu_item(indent, file, path) }
35
- indent.sub!(/^ /, '')
36
- else
37
- file.write("#{indent}#{menu_item}\n")
38
- end
39
- end
40
-
41
- def create_menu(menu_text)
42
- file = filename(Nesta::Config.content_path, 'menu', :txt)
43
- File.open(file, 'w') { |file| file.write(menu_text) }
44
- end
45
-
46
- def delete_page(type, permalink, extension)
47
- file = filename(Nesta::Config.page_path, permalink, extension)
48
- FileUtils.rm(file)
49
- end
50
-
51
- def create_content_directories
52
- FileUtils.mkdir_p(Nesta::Config.page_path)
53
- FileUtils.mkdir_p(Nesta::Config.attachment_path)
54
- end
55
-
56
- def mock_file_stat(method, filename, time)
57
- stat = double(:stat)
58
- stat.stub(:mtime).and_return(Time.parse(time))
59
- File.send(method, :stat).with(filename).and_return(stat)
60
- end
61
-
62
- private
63
- def filename(directory, basename, extension = :mdown)
64
- File.join(directory, "#{basename}.#{extension}")
65
- end
66
-
67
- def heading(options)
68
- prefix = case options[:ext]
69
- when :haml
70
- "%div\n %h1"
71
- when :textile
72
- "<div>\nh1."
73
- else
74
- '# '
75
- end
76
- "#{prefix} #{options[:heading]}\n\n"
77
- end
78
-
79
- def create_file(path, options = {})
80
- create_content_directories
81
- metadata = options[:metadata] || {}
82
- metatext = metadata.map { |key, value| "#{key}: #{value}" }.join("\n")
83
- heading = options[:heading] ? heading(options) : ''
84
- contents =<<-EOF
85
- #{metatext}
86
-
87
- #{heading}#{options[:content]}
88
- EOF
89
- FileUtils.mkdir_p(File.dirname(path))
90
- File.open(path, 'w') { |file| file.write(contents) }
91
- end
92
- end