nesta 0.10.0 → 0.11.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -11
  3. data/.hound.yml +2 -0
  4. data/.travis.yml +2 -1
  5. data/CHANGES +43 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +18 -23
  8. data/lib/nesta/app.rb +0 -5
  9. data/lib/nesta/commands.rb +5 -288
  10. data/lib/nesta/commands/command.rb +58 -0
  11. data/lib/nesta/commands/demo.rb +1 -0
  12. data/lib/nesta/commands/demo/content.rb +38 -0
  13. data/lib/nesta/commands/edit.rb +21 -0
  14. data/lib/nesta/commands/new.rb +57 -0
  15. data/lib/nesta/commands/plugin.rb +1 -0
  16. data/lib/nesta/commands/plugin/create.rb +82 -0
  17. data/lib/nesta/commands/theme.rb +3 -0
  18. data/lib/nesta/commands/theme/create.rb +36 -0
  19. data/lib/nesta/commands/theme/enable.rb +22 -0
  20. data/lib/nesta/commands/theme/install.rb +29 -0
  21. data/lib/nesta/config.rb +1 -6
  22. data/lib/nesta/models.rb +18 -20
  23. data/lib/nesta/version.rb +1 -1
  24. data/nesta.gemspec +1 -0
  25. data/smoke-test.sh +24 -19
  26. data/spec/commands/demo/content_spec.rb +65 -0
  27. data/spec/commands/edit_spec.rb +27 -0
  28. data/spec/commands/new_spec.rb +88 -0
  29. data/spec/commands/plugin/create_spec.rb +97 -0
  30. data/spec/commands/system_spec.rb +25 -0
  31. data/spec/commands/theme/create_spec.rb +41 -0
  32. data/spec/commands/theme/enable_spec.rb +44 -0
  33. data/spec/commands/theme/install_spec.rb +56 -0
  34. data/spec/config_spec.rb +3 -3
  35. data/spec/models_spec.rb +43 -25
  36. data/spec/page_spec.rb +18 -2
  37. data/spec/spec_helper.rb +23 -0
  38. data/templates/Gemfile +1 -1
  39. data/templates/plugins/Gemfile +4 -0
  40. data/templates/plugins/README.md +13 -0
  41. data/templates/plugins/Rakefile +58 -0
  42. data/templates/plugins/gitignore +3 -0
  43. data/templates/plugins/lib/init.rb +13 -0
  44. data/templates/plugins/lib/required.rb +3 -0
  45. data/templates/plugins/lib/version.rb +5 -0
  46. data/templates/plugins/plugin.gemspec +28 -0
  47. data/views/analytics.haml +9 -10
  48. data/views/master.sass +1 -1
  49. metadata +53 -5
  50. data/spec/commands_spec.rb +0 -395
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,56 @@
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
@@ -18,10 +18,10 @@ describe "Config" do
18
18
  @title = "Title from ENV"
19
19
  ENV["NESTA_TITLE"] = @title
20
20
  end
21
-
22
- it "should never try and access config.yml" do
21
+
22
+ it "should fallback to config.yml" do
23
23
  stub_config_key("subtitle", "Subtitle in YAML file")
24
- Nesta::Config.subtitle.should be_nil
24
+ Nesta::Config.subtitle.should == "Subtitle in YAML file"
25
25
  end
26
26
 
27
27
  it "should override config.yml" do
@@ -317,15 +317,6 @@ shared_examples_for "Page" do
317
317
  @article.should_not be_in_category("orange")
318
318
  end
319
319
 
320
- it "should sort categories by link text" do
321
- create_category(heading: "Orange",
322
- metadata: { "link text" => "A citrus fruit" },
323
- path: "orange")
324
- article = create_article(metadata: { "categories" => "apple, orange" })
325
- @article.categories.first.link_text.should == "Apple"
326
- article.categories.first.link_text.should == "A citrus fruit"
327
- end
328
-
329
320
  it "should not be assigned to non-existant category" do
330
321
  delete_page(:category, "banana", @extension)
331
322
  @article.should_not be_in_category("banana")
@@ -540,25 +531,50 @@ end
540
531
  describe "Markdown page" do
541
532
  include ModelFactory
542
533
 
543
- before(:each) do
544
- @extension = :mdown
545
- end
534
+ context "mdown extension" do
535
+ before(:each) do
536
+ @extension = :mdown
537
+ end
546
538
 
547
- include_context "Page testing"
548
- it_should_behave_like "Page"
539
+ include_context "Page testing"
540
+ it_should_behave_like "Page"
549
541
 
550
- it "should set heading from first h1 tag" do
551
- page = create_page(
552
- path: "a-page",
553
- heading: "First heading",
554
- content: "# Second heading"
555
- )
556
- page.heading.should == "First heading"
542
+ it "should set heading from first h1 tag" do
543
+ page = create_page(
544
+ path: "a-page",
545
+ heading: "First heading",
546
+ content: "# Second heading"
547
+ )
548
+ page.heading.should == "First heading"
549
+ end
550
+
551
+ it "should ignore trailing # characters in headings" do
552
+ article = create_article(heading: 'With trailing #')
553
+ article.heading.should == 'With trailing'
554
+ end
557
555
  end
558
556
 
559
- it "should ignore trailing # characters in headings" do
560
- article = create_article(heading: 'With trailing #')
561
- article.heading.should == 'With trailing'
557
+ context "md extension" do
558
+ before(:each) do
559
+ @extension = :md
560
+ end
561
+
562
+ include_context "Page testing"
563
+ it_should_behave_like "Page"
564
+
565
+ it "should set heading from first h1 tag" do
566
+ page = create_page(
567
+ path: "a-page",
568
+ heading: "First heading",
569
+ content: "# Second heading"
570
+ )
571
+ page.heading.should == "First heading"
572
+ end
573
+
574
+ it "should ignore trailing # characters in headings" do
575
+ article = create_article(heading: 'With trailing #')
576
+ article.heading.should == 'With trailing'
577
+ end
562
578
  end
563
579
  end
564
580
 
@@ -635,7 +651,7 @@ describe "Menu" do
635
651
  end
636
652
 
637
653
  it "should find top level menu items" do
638
- text = [@page.path, "no-such-page"].join("\n")
654
+ text = ["no-such-page", @page.path].join("\n")
639
655
  create_menu(text)
640
656
  Nesta::Menu.top_level.should == [@page]
641
657
  end
@@ -656,6 +672,8 @@ describe "Menu" do
656
672
  #{@page2.path}
657
673
  #{@page3.path}
658
674
  #{@page4.path}
675
+ "no-such-page"
676
+ "another-missing-page"
659
677
  #{@page5.path}
660
678
  #{@page6.path}
661
679
  EOF
@@ -110,14 +110,14 @@ describe "The layout" do
110
110
  it "should not include GA JavaScript by default" do
111
111
  stub_configuration
112
112
  get "/"
113
- assert_not_selector "script", content: "'_setAccount', 'UA-1234'"
113
+ assert_not_selector "script", content: "ga('create', 'UA-1234'"
114
114
  end
115
115
 
116
116
  it "should include GA JavaScript if configured" do
117
117
  stub_config_key('google_analytics_code', 'UA-1234', rack_env: true)
118
118
  stub_configuration
119
119
  get "/"
120
- assert_selector 'script', content: "'_setAccount', 'UA-1234'"
120
+ assert_selector 'script', content: "ga('create', 'UA-1234'"
121
121
  end
122
122
  end
123
123
 
@@ -450,6 +450,22 @@ describe "A page" do
450
450
  end
451
451
  end
452
452
  end
453
+
454
+ describe "with associated categories" do
455
+ it "should link to the first assigned category in breadcrumb" do
456
+ category1 = create_category(path: 'category1', heading: 'Category 1')
457
+ create_category(path: 'category2', heading: 'Category 2')
458
+ @category = create_page(
459
+ path: "a-page",
460
+ heading: "A Page",
461
+ metadata: { 'categories' => 'category1, category2' }
462
+ )
463
+ do_get
464
+ href = category1.abspath
465
+ link_text = category1.link_text
466
+ assert_selector "nav.breadcrumb a[href='#{href}']", content: link_text
467
+ end
468
+ end
453
469
  end
454
470
 
455
471
  describe "A Haml page" do
@@ -89,3 +89,26 @@ module RequestSpecHelper
89
89
  body.should_not have_selector(*args)
90
90
  end
91
91
  end
92
+
93
+ shared_context "temporary working directory" do
94
+ before(:each) do
95
+ create_temp_directory
96
+ @project_path = temp_path('mysite.com')
97
+ end
98
+
99
+ after(:each) do
100
+ remove_temp_directory
101
+ end
102
+
103
+ def project_path(path)
104
+ File.join(@project_path, path)
105
+ end
106
+
107
+ def should_exist(file)
108
+ File.exist?(project_path(file)).should be_true
109
+ end
110
+
111
+ def create_config_yaml(text)
112
+ File.open(Nesta::Config.yaml_path, 'w') { |f| f.puts(text) }
113
+ end
114
+ end
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'nesta', '<%= Nesta::VERSION %>'
3
+ gem 'nesta'
4
4
  <% if @options['vlad'] %>gem 'vlad', '2.1.0'
5
5
  gem 'vlad-git', '2.2.0'<% end %>
6
6
 
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in <%= @gem_name %>.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ README
2
+ ======
3
+
4
+ TODO: Explain what your plugin is for
5
+
6
+ Installation
7
+ ------------
8
+
9
+ To use this plugin just add it to your Nesta project's `Gemfile` and
10
+ then install it with Bundler:
11
+
12
+ $ echo 'gem "<%= @gem_name %>"' >> Gemfile
13
+ $ bundle
@@ -0,0 +1,58 @@
1
+ def version
2
+ version_file = File.join(File.dirname(__FILE__), "lib", name, "version.rb")
3
+ contents = File.read(version_file)
4
+ contents.match(/VERSION = ['"]([0-9a-z.-]+)['"].*$/)
5
+ $1
6
+ end
7
+
8
+ def name
9
+ "<%= @gem_name %>"
10
+ end
11
+
12
+ def built_gem_path
13
+ gem_packages = File.join(File.dirname(__FILE__), "pkg", "#{name}-*.gem")
14
+ Dir[gem_packages].sort_by { |file| File.mtime(file) }.last
15
+ end
16
+
17
+ def already_tagged?
18
+ `git tag`.split(/\n/).include?("v#{version}")
19
+ end
20
+
21
+ desc "Build #{name}-#{version}.gem into the pkg directory."
22
+ task 'build' do
23
+ `gem build -V #{File.join(File.dirname(__FILE__), "#{name}.gemspec")}`
24
+ FileUtils.mkdir_p(File.join(File.dirname(__FILE__), "pkg"))
25
+ gem = Dir[File.join(File.dirname(__FILE__), "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
26
+ FileUtils.mv(gem, 'pkg')
27
+ puts "#{name} #{version} built to #{built_gem_path}."
28
+ end
29
+
30
+ desc "Build and install #{name}-#{version}.gem into system gems."
31
+ task 'install' => 'build' do
32
+ `gem install '#{built_gem_path}' --local`
33
+ end
34
+
35
+ desc "Create tag v#{version} and build and push #{name}-#{version}.gem to Rubygems\n" \
36
+ "To prevent publishing in Rubygems use `gem_push=no rake release`"
37
+ task 'release' => ['build', 'release:guard_clean',
38
+ 'release:source_control_push', 'release:rubygem_push'] do
39
+ end
40
+
41
+ task 'release:guard_clean' do
42
+ if !system("git diff --exit-code") || !system("git diff-index --quiet --cached HEAD")
43
+ puts "There are files that need to be committed first."
44
+ exit(1)
45
+ end
46
+ end
47
+
48
+ task 'release:source_control_push' do
49
+ unless already_tagged?
50
+ system "git tag -a -m 'Version #{version}' v#{version}"
51
+ system 'git push'
52
+ system 'git push --tags'
53
+ end
54
+ end
55
+
56
+ task 'release:rubygem_push' do
57
+ system "gem push #{built_gem_path}"
58
+ end
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ pkg/*
@@ -0,0 +1,13 @@
1
+ module Nesta
2
+ module Plugin
3
+ module <%= module_name %>
4
+ module Helpers
5
+ # If your plugin needs any helper methods, add them here...
6
+ end
7
+ end
8
+ end
9
+
10
+ class App
11
+ helpers Nesta::Plugin::<%= module_name %>::Helpers
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require "<%= @gem_name %>/version"
2
+
3
+ Nesta::Plugin.register(__FILE__)
@@ -0,0 +1,5 @@
1
+ module Nesta
2
+ module Plugin
3
+ <%= nested_module_definition_with_version -%>
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "<%= @gem_name %>/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "<%= @gem_name %>"
8
+ spec.version = Nesta::Plugin::<%= module_name %>::VERSION
9
+ spec.authors = ["TODO: Your name"]
10
+ spec.email = ["TODO: Your email address"]
11
+ spec.homepage = ""
12
+ spec.summary = %q{TODO: Write a gem summary}
13
+ spec.description = %q{TODO: Write a gem description}
14
+ spec.license = "MIT"
15
+
16
+ spec.rubyforge_project = "<%= @gem_name %>"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ # spec.add_development_dependency "rspec"
25
+ # spec.add_runtime_dependency "rest-client"
26
+ spec.add_dependency("nesta", ">= 0.9.11")
27
+ spec.add_development_dependency("rake")
28
+ end
@@ -1,12 +1,11 @@
1
1
  - if @google_analytics_code
2
2
  :plain
3
- <script type="text/javascript">
4
- var _gaq = _gaq || [];
5
- _gaq.push(['_setAccount', '#{@google_analytics_code}']);
6
- _gaq.push(['_trackPageview']);
7
- (function() {
8
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
9
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
10
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
11
- })();
12
- </script>
3
+ <script>
4
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
5
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
6
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
7
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
8
+
9
+ ga('create', '#{@google_analytics_code}', 'auto');
10
+ ga('send', 'pageview');
11
+ </script>