nesta 0.9.9 → 0.9.10

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.
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ db/*.db
12
12
  pkg/*
13
13
  plugins
14
14
  public/cache
15
+ spec/tmp
data/CHANGES CHANGED
@@ -1,3 +1,21 @@
1
+ = 0.9.10 / (9 September 2011)
2
+
3
+ * Load Nesta plugins from gems. Any gem whose name begins with
4
+ nesta-plugin- can be used in a project by adding it to the project's
5
+ Gemfile beneath the `gem "nesta"` line. New plugins can be created
6
+ with the `nesta plugin:create` command.
7
+
8
+ * Mark pages as draft by setting a flag. Draft pages won't be shown in
9
+ production, but will be visible on your local copy of your site (as
10
+ it's running in production).
11
+
12
+ * Upgraded Sinatra to version 1.2.6. Upgraded other dependencies to
13
+ latest compatible versions.
14
+
15
+ * Bug fix: The `stylesheet` helper method assumes that you're using
16
+ the Sass rendering engine by default, which allows it to find .sass
17
+ files within the gem if no matching files are found locally.
18
+
1
19
  = 0.9.9 / (24 August 2011)
2
20
 
3
21
  * Bug fix: What a debacle this is turning into. The new Nesta::Env
data/Gemfile.lock CHANGED
@@ -1,52 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nesta (0.9.9)
4
+ nesta (0.9.10)
5
5
  RedCloth (~> 4.2)
6
6
  haml (~> 3.1)
7
7
  maruku (>= 0.6.0)
8
8
  sass (~> 3.1)
9
9
  shotgun (>= 0.8)
10
- sinatra (= 1.1.2)
10
+ sinatra (= 1.2.6)
11
11
 
12
12
  GEM
13
13
  remote: http://rubygems.org/
14
14
  specs:
15
15
  RedCloth (4.2.8)
16
16
  haml (3.1.2)
17
- hoe (2.6.2)
18
- rake (>= 0.8.7)
19
- rubyforge (>= 2.0.4)
20
- hpricot (0.8.3)
21
- json_pure (1.4.6)
17
+ hoe (2.12.2)
18
+ rake (~> 0.8)
19
+ hpricot (0.8.4)
22
20
  maruku (0.6.0)
23
21
  syntax (>= 1.0.0)
24
- rack (1.2.1)
25
- rack-test (0.5.7)
22
+ rack (1.3.2)
23
+ rack-test (0.6.1)
26
24
  rack (>= 1.0)
27
- rake (0.8.7)
25
+ rake (0.9.2)
28
26
  rspec (1.3.0)
29
27
  rspec_hpricot_matchers (1.0)
30
- rubyforge (2.0.4)
31
- json_pure (>= 1.1.7)
32
28
  sass (3.1.7)
33
29
  shotgun (0.9)
34
30
  rack (>= 1.0)
35
- sinatra (1.1.2)
31
+ sinatra (1.2.6)
36
32
  rack (~> 1.1)
37
- tilt (~> 1.2)
33
+ tilt (< 2.0, >= 1.2.2)
38
34
  syntax (1.0.0)
39
35
  test-unit (1.2.3)
40
36
  hoe (>= 1.5.1)
41
- tilt (1.3.2)
37
+ tilt (1.3.3)
42
38
 
43
39
  PLATFORMS
44
40
  ruby
45
41
 
46
42
  DEPENDENCIES
47
- hpricot (= 0.8.3)
43
+ hpricot (= 0.8.4)
48
44
  nesta!
49
- rack-test (= 0.5.7)
45
+ rack-test (= 0.6.1)
50
46
  rspec (= 1.3.0)
51
47
  rspec_hpricot_matchers (= 1.0)
52
48
  test-unit (= 1.2.3)
data/bin/nesta CHANGED
@@ -6,7 +6,7 @@ require File.expand_path('../lib/nesta/commands', File.dirname(__FILE__))
6
6
 
7
7
  module Nesta
8
8
  class Cli
9
- def self.usage
9
+ def self.usage(exitcode=1)
10
10
  puts <<EOF
11
11
  USAGE: #{File.basename($0)} [GLOBAL OPTIONS] <command> [COMMAND OPTIONS]
12
12
 
@@ -17,6 +17,7 @@ GLOBAL OPTIONS
17
17
  COMMANDS
18
18
  new <path> Create a new Nesta project.
19
19
  demo:content Install example pages in ./content-demo.
20
+ plugin:create <name> Create a gem called nesta-plugin-name.
20
21
  theme:install <url> Install a theme from a git repository.
21
22
  theme:enable <name> Make the theme active, updating config.yml.
22
23
  theme:create <name> Makes a template for a new theme in ./themes.
@@ -26,7 +27,7 @@ OPTIONS FOR new
26
27
  --vlad Include config/deploy.rb.
27
28
 
28
29
  EOF
29
- exit 0
30
+ exit exitcode
30
31
  end
31
32
 
32
33
  def self.version
@@ -45,7 +46,7 @@ exit 0
45
46
  opts.each do |opt, arg|
46
47
  case opt
47
48
  when '--help'
48
- usage
49
+ usage(exitcode=0)
49
50
  when '--version'
50
51
  version
51
52
  else
@@ -53,6 +54,9 @@ exit 0
53
54
  end
54
55
  end
55
56
  options
57
+ rescue GetoptLong::InvalidOption => e
58
+ $stderr.puts
59
+ usage
56
60
  end
57
61
 
58
62
  def self.main(options)
@@ -63,12 +67,17 @@ exit 0
63
67
  Nesta::Commands::New.new(ARGV[0], options).execute
64
68
  when 'demo:content'
65
69
  Nesta::Commands::Demo::Content.new.execute
70
+ when 'plugin:create'
71
+ Nesta::Commands::Plugin::Create.new(ARGV[0]).execute
66
72
  when /^theme:(create|enable|install)$/
67
73
  command_cls = Nesta::Commands::Theme.const_get($1.capitalize.to_sym)
68
74
  command_cls.new(ARGV[0], options).execute
69
75
  else
70
- usage
76
+ usage(exitcode=0)
71
77
  end
78
+ rescue RuntimeError => e
79
+ $stderr.puts "ERROR: #{e}"
80
+ exit 1
72
81
  rescue Nesta::Commands::UsageError => e
73
82
  $stderr.puts "ERROR: #{e}"
74
83
  usage
data/lib/nesta/app.rb CHANGED
@@ -10,12 +10,10 @@ require File.expand_path('models', File.dirname(__FILE__))
10
10
  require File.expand_path('navigation', File.dirname(__FILE__))
11
11
  require File.expand_path('overrides', File.dirname(__FILE__))
12
12
  require File.expand_path('path', File.dirname(__FILE__))
13
- require File.expand_path('plugins', File.dirname(__FILE__))
13
+ require File.expand_path('plugin', File.dirname(__FILE__))
14
14
 
15
15
  Encoding.default_external = 'utf-8' if RUBY_VERSION =~ /^1.9/
16
16
 
17
- Nesta::Plugins.load_local_plugins
18
-
19
17
  module Nesta
20
18
  class App < Sinatra::Base
21
19
  register Sinatra::Cache
@@ -112,7 +110,7 @@ module Nesta
112
110
  error do
113
111
  set_common_variables
114
112
  haml(:error)
115
- end unless Nesta::App.environment == :development
113
+ end unless Nesta::App.development?
116
114
 
117
115
  Overrides.load_local_app
118
116
  Overrides.load_theme_app
@@ -163,3 +161,6 @@ module Nesta
163
161
  end
164
162
  end
165
163
  end
164
+
165
+ Nesta::Plugin.load_local_plugins
166
+ Nesta::Plugin.initialize_plugins
@@ -55,7 +55,9 @@ module Nesta
55
55
 
56
56
  def initialize(path, options = {})
57
57
  path.nil? && (raise UsageError.new('path not specified'))
58
- fail("#{path} already exists") if File.exist?(path)
58
+ if File.exist?(path)
59
+ raise RuntimeError.new("#{path} already exists")
60
+ end
59
61
  @path = path
60
62
  @options = options
61
63
  end
@@ -131,6 +133,75 @@ module Nesta
131
133
  end
132
134
  end
133
135
 
136
+ module Plugin
137
+ class Create
138
+ def initialize(name)
139
+ name.nil? && (raise UsageError.new('name not specified'))
140
+ @name = name
141
+ @gem_name = "nesta-plugin-#{name}"
142
+ if File.exist?(@gem_name)
143
+ raise RuntimeError.new("#{@gem_name} already exists")
144
+ end
145
+ end
146
+
147
+ def lib_path(*parts)
148
+ File.join(@gem_name, 'lib', *parts)
149
+ end
150
+
151
+ def modify_required_file
152
+ File.open(lib_path("#{@gem_name}.rb"), 'w') do |file|
153
+ file.write <<-EOF
154
+ require "#{@gem_name}/version"
155
+
156
+ Nesta::Plugin.register(__FILE__)
157
+ EOF
158
+ end
159
+ end
160
+
161
+ def modify_init_file
162
+ module_name = @name.split('-').map { |name| name.capitalize }.join('::')
163
+ File.open(lib_path(@gem_name, 'init.rb'), 'w') do |file|
164
+ file.puts <<-EOF
165
+ module Nesta
166
+ module Plugin
167
+ module #{module_name}
168
+ module Helpers
169
+ helpers do
170
+ # If your plugin needs any helper methods, add them here...
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ class App
177
+ helpers Nesta::Plugin::#{module_name}::Helpers
178
+ end
179
+ end
180
+ EOF
181
+ end
182
+ end
183
+
184
+ def specify_gem_dependency
185
+ File.open(File.join(@gem_name, "#{@gem_name}.gemspec"), 'r+') do |file|
186
+ file.each_line do |line|
187
+ if line =~ /specify any dependencies here/
188
+ file.puts(' s.add_dependency("nesta", ">= 0.9.10")')
189
+ file.puts(' s.add_development_dependency("rake")')
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ def execute
196
+ system('bundle', 'gem', @gem_name)
197
+ modify_required_file
198
+ modify_init_file
199
+ specify_gem_dependency
200
+ Dir.chdir(@gem_name) { system('git', 'add', '.') }
201
+ end
202
+ end
203
+ end
204
+
134
205
  module Theme
135
206
  class Create
136
207
  include Command
data/lib/nesta/models.rb CHANGED
@@ -110,6 +110,11 @@ module Nesta
110
110
  @metadata[key]
111
111
  end
112
112
 
113
+ def flagged_as?(flag)
114
+ flags = metadata("flags")
115
+ flags && flags.split(",").map { |name| name.strip }.include?(flag)
116
+ end
117
+
113
118
  private
114
119
  def markup
115
120
  @markup
@@ -154,7 +159,12 @@ module Nesta
154
159
  end
155
160
 
156
161
  def self.find_by_path(path)
157
- load(path)
162
+ page = load(path)
163
+ page && page.hidden? ? nil : page
164
+ end
165
+
166
+ def self.find_all
167
+ super.select { |p| ! p.hidden? }
158
168
  end
159
169
 
160
170
  def self.find_articles
@@ -167,6 +177,14 @@ module Nesta
167
177
  other.respond_to?(:path) && (self.path == other.path)
168
178
  end
169
179
 
180
+ def draft?
181
+ flagged_as?('draft')
182
+ end
183
+
184
+ def hidden?
185
+ draft? && Nesta::App.production?
186
+ end
187
+
170
188
  def heading
171
189
  regex = case @format
172
190
  when :mdown
@@ -203,11 +221,11 @@ module Nesta
203
221
  end
204
222
 
205
223
  def atom_id
206
- metadata("atom id")
224
+ metadata('atom id')
207
225
  end
208
226
 
209
227
  def read_more
210
- metadata("read more") || "Continue reading"
228
+ metadata('read more') || 'Continue reading'
211
229
  end
212
230
 
213
231
  def summary
@@ -48,7 +48,7 @@ module Nesta
48
48
  end
49
49
  end
50
50
  end
51
- [{}, nil]
51
+ [{}, :sass]
52
52
  end
53
53
 
54
54
  def self.local_view_path
@@ -0,0 +1,33 @@
1
+ module Nesta
2
+ module Plugin
3
+ class << self
4
+ attr_accessor :loaded
5
+ end
6
+ self.loaded ||= []
7
+
8
+ def self.register(path)
9
+ name = File.basename(path, '.rb')
10
+ prefix = 'nesta-plugin-'
11
+ name.start_with?(prefix) || raise("Plugin names must match '#{prefix}*'")
12
+ self.loaded << name
13
+ end
14
+
15
+ def self.initialize_plugins
16
+ self.loaded.each { |name| require "#{name}/init" }
17
+ end
18
+
19
+ def self.load_local_plugins
20
+ plugins = Dir.glob(File.expand_path('../plugins/*', File.dirname(__FILE__)))
21
+ plugins.each { |path| require_local_plugin(path) }
22
+ end
23
+
24
+ private
25
+ def self.require_local_plugin(path)
26
+ Nesta.deprecated(
27
+ 'loading plugins from ./plugins', "convert #{path} to a gem")
28
+ require File.join(path, 'lib', File.basename(path))
29
+ rescue LoadError => e
30
+ $stderr.write("Couldn't load plugins/#{File.basename(path)}: #{e}\n")
31
+ end
32
+ end
33
+ end
data/lib/nesta/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nesta
2
- VERSION = '0.9.9'
2
+ VERSION = '0.9.10'
3
3
  end
data/nesta.gemspec CHANGED
@@ -35,14 +35,14 @@ EOF
35
35
  s.add_dependency('sass', '~> 3.1')
36
36
  s.add_dependency('maruku', '>= 0.6.0')
37
37
  s.add_dependency('RedCloth', '~> 4.2')
38
- s.add_dependency('sinatra', '1.1.2')
38
+ s.add_dependency('sinatra', '1.2.6')
39
39
 
40
40
  # Useful in development
41
41
  s.add_dependency('shotgun', '>= 0.8')
42
42
 
43
43
  # Test libraries
44
- s.add_development_dependency('hpricot', '0.8.3')
45
- s.add_development_dependency('rack-test', '0.5.7')
44
+ s.add_development_dependency('hpricot', '0.8.4')
45
+ s.add_development_dependency('rack-test', '0.6.1')
46
46
  s.add_development_dependency('rspec', '1.3.0')
47
47
  s.add_development_dependency('rspec_hpricot_matchers', '1.0')
48
48
  s.add_development_dependency('test-unit', '1.2.3')
data/spec/atom_spec.rb CHANGED
@@ -2,7 +2,6 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
  require File.expand_path('model_factory', File.dirname(__FILE__))
3
3
 
4
4
  describe "atom feed" do
5
- include ConfigSpecHelper
6
5
  include ModelFactory
7
6
  include RequestSpecHelper
8
7
 
@@ -17,7 +16,7 @@ describe "atom feed" do
17
16
  end
18
17
 
19
18
  after(:each) do
20
- remove_fixtures
19
+ remove_temp_directory
21
20
  end
22
21
 
23
22
  it "should render successfully" do
@@ -2,15 +2,13 @@ require File.expand_path("spec_helper", File.dirname(__FILE__))
2
2
  require File.expand_path("../lib/nesta/commands", File.dirname(__FILE__))
3
3
 
4
4
  describe "nesta" do
5
- include FixtureHelper
6
-
7
5
  before(:each) do
8
- create_fixtures_directory
9
- @project_path = File.join(FixtureHelper::FIXTURE_DIR, 'mysite.com')
6
+ create_temp_directory
7
+ @project_path = temp_path('mysite.com')
10
8
  end
11
9
 
12
10
  after(:each) do
13
- remove_fixtures
11
+ remove_temp_directory
14
12
  end
15
13
 
16
14
  def project_path(path)
@@ -169,6 +167,80 @@ describe "nesta" do
169
167
  end
170
168
  end
171
169
 
170
+ describe "plugin:create" do
171
+ before(:each) do
172
+ @name = 'my-feature'
173
+ @gem_name = "nesta-plugin-#{@name}"
174
+ @plugins_path = temp_path('plugins')
175
+ @working_dir = Dir.pwd
176
+ Dir.mkdir(@plugins_path)
177
+ Dir.chdir(@plugins_path)
178
+ @command = Nesta::Commands::Plugin::Create.new(@name)
179
+ @command.stub!(:system)
180
+ end
181
+
182
+ after(:each) do
183
+ Dir.chdir(@working_dir)
184
+ FileUtils.rm_r(@plugins_path)
185
+ end
186
+
187
+ it "should create a new gem prefixed with nesta-plugin" do
188
+ @command.should_receive(:system).with('bundle', 'gem', @gem_name)
189
+ begin
190
+ @command.execute
191
+ rescue Errno::ENOENT
192
+ # This test is only concerned with running bundle gem; ENOENT
193
+ # errors are raised because we didn't create a real gem.
194
+ end
195
+ end
196
+
197
+ describe "after gem created" do
198
+ def create_gem_file(*components)
199
+ path = File.join(@plugins_path, @gem_name, *components)
200
+ FileUtils.makedirs(File.dirname(path))
201
+ File.open(path, 'w') { |f| yield f if block_given? }
202
+ path
203
+ end
204
+
205
+ before(:each) do
206
+ @required_file = create_gem_file('lib', "#{@gem_name}.rb")
207
+ @init_file = create_gem_file('lib', @gem_name, 'init.rb')
208
+ @gem_spec = create_gem_file("#{@gem_name}.gemspec") do |file|
209
+ file.puts " # specify any dependencies here; for example:"
210
+ end
211
+ end
212
+
213
+ after(:each) do
214
+ FileUtils.rm(@required_file)
215
+ FileUtils.rm(@init_file)
216
+ end
217
+
218
+ it "should create the ruby file loaded on require" do
219
+ @command.execute
220
+ File.read(@required_file).should include('Plugin.register(__FILE__)')
221
+ end
222
+
223
+ it "should create a default init.rb file" do
224
+ @command.execute
225
+ init = File.read(@init_file)
226
+ boilerplate = <<-EOF
227
+ module My::Feature
228
+ module Helpers
229
+ helpers do
230
+ EOF
231
+ init.should include(boilerplate)
232
+ init.should include('helpers Nesta::Plugin::My::Feature::Helpers')
233
+ end
234
+
235
+ it "should specify plugin gem's dependencies" do
236
+ @command.execute
237
+ text = File.read(@gem_spec)
238
+ text.should include('s.add_dependency("nesta", ">= 0.9.10")')
239
+ text.should include('s.add_development_dependency("rake")')
240
+ end
241
+ end
242
+ end
243
+
172
244
  describe "theme:install" do
173
245
  before(:each) do
174
246
  @repo_url = 'git://github.com/gma/nesta-theme-mine.git'
@@ -221,7 +293,7 @@ describe "nesta" do
221
293
 
222
294
  describe "theme:enable" do
223
295
  before(:each) do
224
- config = File.join(FixtureHelper::FIXTURE_DIR, 'config.yml')
296
+ config = temp_path('config.yml')
225
297
  Nesta::Config.stub!(:yaml_path).and_return(config)
226
298
  @name = 'mytheme'
227
299
  @command = Nesta::Commands::Theme::Enable.new(@name)
@@ -265,7 +337,7 @@ describe "nesta" do
265
337
  end
266
338
 
267
339
  before(:each) do
268
- Nesta::App.stub!(:root).and_return(FixtureHelper::FIXTURE_DIR)
340
+ Nesta::App.stub!(:root).and_return(TempFileHelper::TEMP_DIR)
269
341
  @name = 'my-new-theme'
270
342
  Nesta::Commands::Theme::Create.new(@name).execute
271
343
  end