nesta 0.9.11 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -11
  3. data/.gitmodules +6 -0
  4. data/.hound.yml +2 -0
  5. data/{spec/spec.opts → .rspec} +0 -0
  6. data/.travis.yml +11 -0
  7. data/CHANGES +250 -2
  8. data/Gemfile +2 -2
  9. data/Gemfile.lock +89 -33
  10. data/Guardfile +7 -0
  11. data/LICENSE +1 -1
  12. data/README.md +38 -6
  13. data/RELEASING.md +21 -0
  14. data/Rakefile +20 -4
  15. data/bin/nesta +131 -14
  16. data/config.ru +3 -0
  17. data/lib/nesta.rb +9 -1
  18. data/lib/nesta/app.rb +21 -107
  19. data/lib/nesta/commands.rb +5 -256
  20. data/lib/nesta/commands/command.rb +57 -0
  21. data/lib/nesta/commands/demo.rb +1 -0
  22. data/lib/nesta/commands/demo/content.rb +56 -0
  23. data/lib/nesta/commands/edit.rb +21 -0
  24. data/lib/nesta/commands/new.rb +57 -0
  25. data/lib/nesta/commands/plugin.rb +1 -0
  26. data/lib/nesta/commands/plugin/create.rb +82 -0
  27. data/lib/nesta/commands/theme.rb +3 -0
  28. data/lib/nesta/commands/theme/create.rb +36 -0
  29. data/lib/nesta/commands/theme/enable.rb +22 -0
  30. data/lib/nesta/commands/theme/install.rb +31 -0
  31. data/lib/nesta/config.rb +51 -22
  32. data/lib/nesta/helpers.rb +115 -0
  33. data/lib/nesta/models.rb +111 -70
  34. data/lib/nesta/navigation.rb +36 -12
  35. data/lib/nesta/overrides.rb +10 -5
  36. data/lib/nesta/plugin.rb +10 -8
  37. data/lib/nesta/version.rb +1 -1
  38. data/nesta.gemspec +14 -13
  39. data/templates/Gemfile +6 -3
  40. data/templates/config.ru +3 -0
  41. data/templates/config/config.yml +14 -14
  42. data/templates/config/deploy.rb +2 -2
  43. data/templates/index.haml +2 -0
  44. data/templates/plugins/Gemfile +4 -0
  45. data/templates/plugins/README.md +13 -0
  46. data/templates/plugins/Rakefile +58 -0
  47. data/templates/plugins/gitignore +3 -0
  48. data/templates/plugins/lib/init.rb +13 -0
  49. data/templates/plugins/lib/required.rb +3 -0
  50. data/templates/plugins/lib/version.rb +5 -0
  51. data/templates/plugins/plugin.gemspec +28 -0
  52. data/templates/themes/README.md +1 -1
  53. data/templates/themes/app.rb +1 -1
  54. data/templates/themes/views/layout.haml +7 -0
  55. data/templates/themes/views/master.sass +3 -0
  56. data/templates/themes/views/page.haml +1 -0
  57. data/{spec → test}/fixtures/nesta-plugin-test/Gemfile +0 -0
  58. data/{spec → test}/fixtures/nesta-plugin-test/Rakefile +0 -0
  59. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test.rb +0 -0
  60. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/init.rb +1 -3
  61. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/version.rb +0 -0
  62. data/{spec → test}/fixtures/nesta-plugin-test/nesta-plugin-test.gemspec +0 -0
  63. data/test/integration/atom_feed_test.rb +178 -0
  64. data/test/integration/commands/demo/content_test.rb +31 -0
  65. data/test/integration/commands/edit_test.rb +21 -0
  66. data/test/integration/commands/new_test.rb +120 -0
  67. data/test/integration/commands/plugin/create_test.rb +128 -0
  68. data/test/integration/commands/theme/create_test.rb +35 -0
  69. data/test/integration/commands/theme/enable_test.rb +22 -0
  70. data/test/integration/commands/theme/install_test.rb +62 -0
  71. data/test/integration/default_theme_test.rb +220 -0
  72. data/test/integration/overrides_test.rb +118 -0
  73. data/test/integration/route_handlers_test.rb +96 -0
  74. data/test/integration/sitemap_test.rb +85 -0
  75. data/test/integration_test_helper.rb +61 -0
  76. data/test/support/model_factory.rb +169 -0
  77. data/test/support/silence_commands_during_tests.rb +5 -0
  78. data/test/support/temporary_files.rb +33 -0
  79. data/test/support/test_configuration.rb +19 -0
  80. data/test/test_helper.rb +26 -0
  81. data/test/unit/commands_test.rb +23 -0
  82. data/test/unit/config_test.rb +138 -0
  83. data/test/unit/file_model_test.rb +71 -0
  84. data/test/unit/menu_test.rb +82 -0
  85. data/test/unit/page_test.rb +571 -0
  86. data/test/unit/path_test.rb +41 -0
  87. data/test/unit/plugin_test.rb +47 -0
  88. data/views/analytics.haml +9 -10
  89. data/views/atom.haml +4 -4
  90. data/views/comments.haml +1 -1
  91. data/views/error.haml +1 -1
  92. data/views/feed.haml +1 -1
  93. data/views/layout.haml +6 -3
  94. data/views/master.sass +144 -134
  95. data/views/mixins.sass +53 -28
  96. data/views/normalize.scss +396 -0
  97. data/views/page_meta.haml +2 -2
  98. data/views/sitemap.haml +2 -2
  99. data/views/summaries.haml +2 -2
  100. metadata +258 -232
  101. data/lib/nesta/cache.rb +0 -139
  102. data/lib/nesta/nesta.rb +0 -7
  103. data/spec/atom_spec.rb +0 -138
  104. data/spec/commands_spec.rb +0 -364
  105. data/spec/config_spec.rb +0 -67
  106. data/spec/model_factory.rb +0 -92
  107. data/spec/models_spec.rb +0 -588
  108. data/spec/overrides_spec.rb +0 -132
  109. data/spec/page_spec.rb +0 -498
  110. data/spec/path_spec.rb +0 -28
  111. data/spec/plugin_spec.rb +0 -51
  112. data/spec/sitemap_spec.rb +0 -100
  113. data/spec/spec_helper.rb +0 -76
@@ -6,259 +6,8 @@ require File.expand_path('app', File.dirname(__FILE__))
6
6
  require File.expand_path('path', File.dirname(__FILE__))
7
7
  require File.expand_path('version', File.dirname(__FILE__))
8
8
 
9
- module Nesta
10
- module Commands
11
- class UsageError < RuntimeError; end
12
-
13
- module Command
14
- def fail(message)
15
- $stderr.puts "Error: #{message}"
16
- exit 1
17
- end
18
-
19
- def template_root
20
- File.expand_path('../../templates', File.dirname(__FILE__))
21
- end
22
-
23
- def copy_template(src, dest)
24
- FileUtils.mkdir_p(File.dirname(dest))
25
- template = ERB.new(File.read(File.join(template_root, src)))
26
- File.open(dest, 'w') { |file| file.puts template.result(binding) }
27
- end
28
-
29
- def copy_templates(templates)
30
- templates.each { |src, dest| copy_template(src, dest) }
31
- end
32
-
33
- def update_config_yaml(pattern, replacement)
34
- configured = false
35
- File.open(Nesta::Config.yaml_path, 'r+') do |file|
36
- output = ''
37
- file.each_line do |line|
38
- if configured
39
- output << line
40
- else
41
- output << line.sub(pattern, replacement)
42
- configured = true if line =~ pattern
43
- end
44
- end
45
- output << "#{replacement}\n" unless configured
46
- file.pos = 0
47
- file.print(output)
48
- file.truncate(file.pos)
49
- end
50
- end
51
- end
52
-
53
- class New
54
- include Command
55
-
56
- def initialize(path, options = {})
57
- path.nil? && (raise UsageError.new('path not specified'))
58
- if File.exist?(path)
59
- raise RuntimeError.new("#{path} already exists")
60
- end
61
- @path = path
62
- @options = options
63
- end
64
-
65
- def make_directories
66
- %w[content/attachments content/pages].each do |dir|
67
- FileUtils.mkdir_p(File.join(@path, dir))
68
- end
69
- end
70
-
71
- def have_rake_tasks?
72
- @options['vlad']
73
- end
74
-
75
- def create_repository
76
- FileUtils.cd(@path) do
77
- File.open('.gitignore', 'w') do |file|
78
- file.puts %w[._* .*.swp .bundle .DS_Store .sass-cache].join("\n")
79
- end
80
- system('git', 'init')
81
- system('git', 'add', '.')
82
- system('git', 'commit', '-m', 'Initial commit')
83
- end
84
- end
85
-
86
- def execute
87
- make_directories
88
- templates = {
89
- 'config.ru' => "#{@path}/config.ru",
90
- 'config/config.yml' => "#{@path}/config/config.yml",
91
- 'index.haml' => "#{@path}/content/pages/index.haml",
92
- 'Gemfile' => "#{@path}/Gemfile"
93
- }
94
- templates['Rakefile'] = "#{@path}/Rakefile" if have_rake_tasks?
95
- if @options['vlad']
96
- templates['config/deploy.rb'] = "#{@path}/config/deploy.rb"
97
- end
98
- copy_templates(templates)
99
- create_repository if @options['git']
100
- end
101
- end
102
-
103
- module Demo
104
- class Content
105
- include Command
106
-
107
- def initialize
108
- @dir = 'content-demo'
109
- end
110
-
111
- def clone_or_update_repository
112
- repository = 'git://github.com/gma/nesta-demo-content.git'
113
- path = Nesta::Path.local(@dir)
114
- if File.exist?(path)
115
- FileUtils.cd(path) { system('git', 'pull', 'origin', 'master') }
116
- else
117
- system('git', 'clone', repository, path)
118
- end
119
- end
120
-
121
- def configure_git_to_ignore_repo
122
- excludes = Nesta::Path.local('.git/info/exclude')
123
- if File.exist?(excludes) && File.read(excludes).scan(@dir).empty?
124
- File.open(excludes, 'a') { |file| file.puts @dir }
125
- end
126
- end
127
-
128
- def execute
129
- clone_or_update_repository
130
- configure_git_to_ignore_repo
131
- update_config_yaml(/^\s*#?\s*content:.*/, "content: #{@dir}")
132
- end
133
- end
134
- end
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
- # If your plugin needs any helper methods, add them here...
170
- end
171
- end
172
- end
173
-
174
- class App
175
- helpers Nesta::Plugin::#{module_name}::Helpers
176
- end
177
- end
178
- EOF
179
- end
180
- end
181
-
182
- def specify_gem_dependency
183
- gemspec = File.join(@gem_name, "#{@gem_name}.gemspec")
184
- File.open(gemspec, 'r+') do |file|
185
- output = ''
186
- file.each_line do |line|
187
- if line =~ /^end/
188
- output << ' s.add_dependency("nesta", ">= 0.9.11")' + "\n"
189
- output << ' s.add_development_dependency("rake")' + "\n"
190
- end
191
- output << line
192
- end
193
- file.pos = 0
194
- file.print(output)
195
- file.truncate(file.pos)
196
- end
197
- end
198
-
199
- def execute
200
- system('bundle', 'gem', @gem_name)
201
- modify_required_file
202
- modify_init_file
203
- specify_gem_dependency
204
- Dir.chdir(@gem_name) { system('git', 'add', '.') }
205
- end
206
- end
207
- end
208
-
209
- module Theme
210
- class Create
211
- include Command
212
-
213
- def initialize(name, options = {})
214
- name.nil? && (raise UsageError.new('name not specified'))
215
- @name = name
216
- @theme_path = Nesta::Path.themes(@name)
217
- fail("#{@theme_path} already exists") if File.exist?(@theme_path)
218
- end
219
-
220
- def make_directories
221
- FileUtils.mkdir_p(File.join(@theme_path, 'public', @name))
222
- FileUtils.mkdir_p(File.join(@theme_path, 'views'))
223
- end
224
-
225
- def execute
226
- make_directories
227
- copy_templates(
228
- 'themes/README.md' => "#{@theme_path}/README.md",
229
- 'themes/app.rb' => "#{@theme_path}/app.rb"
230
- )
231
- end
232
- end
233
-
234
- class Install
235
- include Command
236
-
237
- def initialize(url, options = {})
238
- url.nil? && (raise UsageError.new('URL not specified'))
239
- @url = url
240
- @name = File.basename(url, '.git').sub(/nesta-theme-/, '')
241
- end
242
-
243
- def execute
244
- system('git', 'clone', @url, "themes/#{@name}")
245
- FileUtils.rm_r(File.join("themes/#{@name}", '.git'))
246
- enable(@name)
247
- end
248
- end
249
-
250
- class Enable
251
- include Command
252
-
253
- def initialize(name, options = {})
254
- name.nil? && (raise UsageError.new('name not specified'))
255
- @name = name
256
- end
257
-
258
- def execute
259
- update_config_yaml(/^\s*#?\s*theme:.*/, "theme: #{@name}")
260
- end
261
- end
262
- end
263
- end
264
- end
9
+ require File.expand_path('commands/demo', File.dirname(__FILE__))
10
+ require File.expand_path('commands/edit', File.dirname(__FILE__))
11
+ require File.expand_path('commands/new', File.dirname(__FILE__))
12
+ require File.expand_path('commands/plugin', File.dirname(__FILE__))
13
+ require File.expand_path('commands/theme', File.dirname(__FILE__))
@@ -0,0 +1,57 @@
1
+ module Nesta
2
+ module Commands
3
+ class UsageError < RuntimeError; end
4
+
5
+ module Command
6
+ def run_process(*args)
7
+ system(*args)
8
+ if ! $?.success?
9
+ message = if $?.exitstatus == 127
10
+ "#{args[0]} not found"
11
+ else
12
+ "'#{args.join(' ')}' failed with status #{$?.exitstatus}"
13
+ end
14
+ fail(message)
15
+ end
16
+ end
17
+
18
+ def fail(message)
19
+ $stderr.puts "Error: #{message}"
20
+ exit 1
21
+ end
22
+
23
+ def template_root
24
+ File.expand_path('../../../templates', File.dirname(__FILE__))
25
+ end
26
+
27
+ def copy_template(src, dest)
28
+ FileUtils.mkdir_p(File.dirname(dest))
29
+ template = ERB.new(File.read(File.join(template_root, src)), nil, "-")
30
+ File.open(dest, 'w') { |file| file.puts template.result(binding) }
31
+ end
32
+
33
+ def copy_templates(templates)
34
+ templates.each { |src, dest| copy_template(src, dest) }
35
+ end
36
+
37
+ def update_config_yaml(pattern, replacement)
38
+ configured = false
39
+ File.open(Nesta::Config.yaml_path, 'r+') do |file|
40
+ output = ''
41
+ file.each_line do |line|
42
+ if configured
43
+ output << line
44
+ else
45
+ output << line.sub(pattern, replacement)
46
+ configured = true if line =~ pattern
47
+ end
48
+ end
49
+ output << "#{replacement}\n" unless configured
50
+ file.pos = 0
51
+ file.print(output)
52
+ file.truncate(file.pos)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('demo/content', File.dirname(__FILE__))
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../command', File.dirname(__FILE__))
2
+
3
+ module Nesta
4
+ module Commands
5
+ module Demo
6
+ class Content
7
+ include Command
8
+
9
+ @demo_repository = 'git://github.com/gma/nesta-demo-content.git'
10
+ class << self
11
+ attr_accessor :demo_repository
12
+ end
13
+
14
+ def initialize(*args)
15
+ @dir = 'content-demo'
16
+ end
17
+
18
+ def clone_or_update_repository
19
+ path = Nesta::Path.local(@dir)
20
+ if File.exist?(path)
21
+ FileUtils.cd(path) { run_process('git', 'pull', 'origin', 'master') }
22
+ else
23
+ run_process('git', 'clone', self.class.demo_repository, path)
24
+ end
25
+ end
26
+
27
+ def exclude_path
28
+ Nesta::Path.local('.git/info/exclude')
29
+ end
30
+
31
+ def in_git_repo?
32
+ File.directory?(Nesta::Path.local('.git'))
33
+ end
34
+
35
+ def demo_repo_ignored?
36
+ File.read(exclude_path).split.any? { |line| line == @dir }
37
+ rescue Errno::ENOENT
38
+ false
39
+ end
40
+
41
+ def configure_git_to_ignore_repo
42
+ if in_git_repo? && ! demo_repo_ignored?
43
+ FileUtils.mkdir_p(File.dirname(exclude_path))
44
+ File.open(exclude_path, 'a') { |file| file.puts @dir }
45
+ end
46
+ end
47
+
48
+ def execute
49
+ clone_or_update_repository
50
+ configure_git_to_ignore_repo
51
+ update_config_yaml(/^\s*#?\s*content:.*/, "content: #{@dir}")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('command', File.dirname(__FILE__))
2
+
3
+ module Nesta
4
+ module Commands
5
+ class Edit
6
+ include Command
7
+
8
+ def initialize(*args)
9
+ @filename = Nesta::Config.page_path(args.shift)
10
+ end
11
+
12
+ def execute
13
+ editor = ENV.fetch('EDITOR')
14
+ rescue IndexError
15
+ $stderr.puts "No editor: set EDITOR environment variable"
16
+ else
17
+ run_process(editor, @filename)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('command', File.dirname(__FILE__))
2
+
3
+ module Nesta
4
+ module Commands
5
+ class New
6
+ include Command
7
+
8
+ def initialize(*args)
9
+ path = args.shift
10
+ options = args.shift || {}
11
+ path.nil? && (raise UsageError.new('path not specified'))
12
+ if File.exist?(path)
13
+ raise RuntimeError.new("#{path} already exists")
14
+ end
15
+ @path = path
16
+ @options = options
17
+ end
18
+
19
+ def make_directories
20
+ %w[content/attachments content/pages].each do |dir|
21
+ FileUtils.mkdir_p(File.join(@path, dir))
22
+ end
23
+ end
24
+
25
+ def have_rake_tasks?
26
+ @options['vlad']
27
+ end
28
+
29
+ def create_repository
30
+ FileUtils.cd(@path) do
31
+ File.open('.gitignore', 'w') do |file|
32
+ file.puts %w[._* .*.swp .bundle .DS_Store .sass-cache].join("\n")
33
+ end
34
+ run_process('git', 'init')
35
+ run_process('git', 'add', '.')
36
+ run_process('git', 'commit', '-m', 'Initial commit')
37
+ end
38
+ end
39
+
40
+ def execute
41
+ make_directories
42
+ templates = {
43
+ 'config.ru' => "#{@path}/config.ru",
44
+ 'config/config.yml' => "#{@path}/config/config.yml",
45
+ 'index.haml' => "#{@path}/content/pages/index.haml",
46
+ 'Gemfile' => "#{@path}/Gemfile"
47
+ }
48
+ templates['Rakefile'] = "#{@path}/Rakefile" if have_rake_tasks?
49
+ if @options['vlad']
50
+ templates['config/deploy.rb'] = "#{@path}/config/deploy.rb"
51
+ end
52
+ copy_templates(templates)
53
+ create_repository if @options['git']
54
+ end
55
+ end
56
+ end
57
+ end