machined 0.7.1 → 0.8.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 (43) hide show
  1. data/Rakefile +2 -2
  2. data/bin/machined +3 -3
  3. data/lib/machined.rb +17 -17
  4. data/lib/machined/cli.rb +35 -35
  5. data/lib/machined/context.rb +4 -4
  6. data/lib/machined/environment.rb +57 -31
  7. data/lib/machined/helpers/asset_tag_helpers.rb +4 -4
  8. data/lib/machined/helpers/locals_helpers.rb +1 -1
  9. data/lib/machined/helpers/output_helpers.rb +15 -15
  10. data/lib/machined/helpers/page_helpers.rb +1 -1
  11. data/lib/machined/helpers/render_helpers.rb +16 -16
  12. data/lib/machined/index.rb +1 -1
  13. data/lib/machined/initializable.rb +9 -11
  14. data/lib/machined/processors/front_matter_processor.rb +2 -2
  15. data/lib/machined/processors/layout_processor.rb +1 -1
  16. data/lib/machined/server.rb +2 -2
  17. data/lib/machined/sprocket.rb +4 -4
  18. data/lib/machined/static_compiler.rb +2 -2
  19. data/lib/machined/templates/site/Gemfile.tt +4 -4
  20. data/lib/machined/templates/site/config.ru +1 -1
  21. data/lib/machined/templates/site/machined.rb +2 -2
  22. data/lib/machined/templates/site/views/layouts/application.html.erb +2 -2
  23. data/lib/machined/utils.rb +3 -3
  24. data/lib/machined/version.rb +1 -1
  25. data/machined.gemspec +29 -31
  26. data/spec/machined/cli_spec.rb +56 -56
  27. data/spec/machined/context_spec.rb +6 -6
  28. data/spec/machined/environment_spec.rb +94 -94
  29. data/spec/machined/helpers/asset_tag_helpers_spec.rb +42 -42
  30. data/spec/machined/helpers/locals_helper_spec.rb +17 -17
  31. data/spec/machined/helpers/output_helpers_spec.rb +27 -27
  32. data/spec/machined/helpers/page_helpers_spec.rb +32 -32
  33. data/spec/machined/helpers/render_helpers_spec.rb +42 -42
  34. data/spec/machined/initializable_spec.rb +9 -9
  35. data/spec/machined/processors/front_matter_processor_spec.rb +7 -7
  36. data/spec/machined/processors/layout_processor_spec.rb +19 -19
  37. data/spec/machined/server_spec.rb +36 -36
  38. data/spec/machined/sprocket_spec.rb +15 -15
  39. data/spec/machined/utils_spec.rb +14 -14
  40. data/spec/spec_helper.rb +7 -7
  41. data/spec/support/be_fresh_matcher.rb +2 -2
  42. data/spec/support/helpers.rb +6 -6
  43. metadata +177 -301
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
- require "rspec/core/rake_task"
3
+ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
6
  task :default => :spec
data/bin/machined CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["BUNDLE_GEMFILE"] ||= File.join(Dir.pwd, "Gemfile")
4
- require "bundler/setup" if File.exist? ENV["BUNDLE_GEMFILE"]
3
+ ENV['BUNDLE_GEMFILE'] ||= File.join(Dir.pwd, 'Gemfile')
4
+ require 'bundler/setup' if File.exist? ENV['BUNDLE_GEMFILE']
5
5
 
6
- require "machined"
6
+ require 'machined'
7
7
  Machined::CLI.start
data/lib/machined.rb CHANGED
@@ -1,26 +1,26 @@
1
- require "machined/version"
1
+ require 'machined/version'
2
2
 
3
3
  module Machined
4
- autoload :CLI, "machined/cli"
5
- autoload :Context, "machined/context"
6
- autoload :Environment, "machined/environment"
7
- autoload :Index, "machined/index"
8
- autoload :Initializable, "machined/initializable"
9
- autoload :Server, "machined/server"
10
- autoload :Sprocket, "machined/sprocket"
11
- autoload :StaticCompiler, "machined/static_compiler"
12
- autoload :Utils, "machined/utils"
4
+ autoload :CLI, 'machined/cli'
5
+ autoload :Context, 'machined/context'
6
+ autoload :Environment, 'machined/environment'
7
+ autoload :Index, 'machined/index'
8
+ autoload :Initializable, 'machined/initializable'
9
+ autoload :Server, 'machined/server'
10
+ autoload :Sprocket, 'machined/sprocket'
11
+ autoload :StaticCompiler, 'machined/static_compiler'
12
+ autoload :Utils, 'machined/utils'
13
13
 
14
14
  module Helpers
15
- autoload :AssetTagHelpers, "machined/helpers/asset_tag_helpers"
16
- autoload :LocalsHelpers, "machined/helpers/locals_helpers"
17
- autoload :OutputHelpers, "machined/helpers/output_helpers"
18
- autoload :PageHelpers, "machined/helpers/page_helpers"
19
- autoload :RenderHelpers, "machined/helpers/render_helpers"
15
+ autoload :AssetTagHelpers, 'machined/helpers/asset_tag_helpers'
16
+ autoload :LocalsHelpers, 'machined/helpers/locals_helpers'
17
+ autoload :OutputHelpers, 'machined/helpers/output_helpers'
18
+ autoload :PageHelpers, 'machined/helpers/page_helpers'
19
+ autoload :RenderHelpers, 'machined/helpers/render_helpers'
20
20
  end
21
21
 
22
22
  module Processors
23
- autoload :FrontMatterProcessor, "machined/processors/front_matter_processor"
24
- autoload :LayoutProcessor, "machined/processors/layout_processor"
23
+ autoload :FrontMatterProcessor, 'machined/processors/front_matter_processor'
24
+ autoload :LayoutProcessor, 'machined/processors/layout_processor'
25
25
  end
26
26
  end
data/lib/machined/cli.rb CHANGED
@@ -1,60 +1,60 @@
1
- require "active_support/core_ext/hash/keys"
2
- require "active_support/core_ext/hash/slice"
3
- require "thor"
1
+ require 'active_support/core_ext/hash/keys'
2
+ require 'active_support/core_ext/hash/slice'
3
+ require 'thor'
4
4
 
5
5
  module Machined
6
6
  class CLI < Thor
7
7
  include Thor::Actions
8
8
 
9
9
  default_task :help
10
- source_root File.expand_path("../templates", __FILE__)
10
+ source_root File.expand_path('../templates', __FILE__)
11
11
 
12
- class_option "root", :aliases => "-r",
13
- :desc => "Path to the root directory of the project",
14
- :default => "."
15
- class_option "config_path", :aliases => "-c",
16
- :desc => "Path to the config file",
17
- :default => "machined.rb"
18
- class_option "output_path", :aliases => "-o",
19
- :desc => "Path to the output directory of the project",
20
- :default => "public"
21
- class_option "environment", :aliases => "-e",
22
- :desc => "Sets the environment",
23
- :default => "development"
12
+ class_option 'root', :aliases => '-r',
13
+ :desc => 'Path to the root directory of the project',
14
+ :default => '.'
15
+ class_option 'config_path', :aliases => '-c',
16
+ :desc => 'Path to the config file',
17
+ :default => 'machined.rb'
18
+ class_option 'output_path', :aliases => '-o',
19
+ :desc => 'Path to the output directory of the project',
20
+ :default => 'public'
21
+ class_option 'environment', :aliases => '-e',
22
+ :desc => 'Sets the environment',
23
+ :default => 'development'
24
24
 
25
- desc "compile", "Compiles the site from the source files"
25
+ desc 'compile', 'Compiles the site from the source files'
26
26
  def compile
27
27
  machined.compile
28
28
  end
29
29
  map %w(c build b) => :compile
30
30
 
31
- desc "new SITE_NAME", "Generates a new site with the give name"
31
+ desc 'new SITE_NAME', 'Generates a new site with the give name'
32
32
  def new(site_name)
33
- directory "site", site_name
33
+ directory 'site', site_name
34
34
  end
35
35
  map %w(n generate g) => :new
36
36
 
37
- desc "server", "Runs a local Rack based web server"
38
- method_option :port, :aliases => "-p",
39
- :desc => "Serve at the given port",
37
+ desc 'server', 'Runs a local Rack based web server'
38
+ method_option :port, :aliases => '-p',
39
+ :desc => 'Serve at the given port',
40
40
  :type => :numeric, :default => 3000
41
- method_option :host, :aliases => "-h",
42
- :desc => "Listen on the given given host",
43
- :default => "0.0.0.0"
44
- method_option :server, :aliases => "-s",
45
- :desc => "Serve with the given handler"
46
- method_option :daemonize, :aliases => "-D",
47
- :desc => "Run daemonized in the background",
41
+ method_option :host, :aliases => '-h',
42
+ :desc => 'Listen on the given given host',
43
+ :default => '0.0.0.0'
44
+ method_option :server, :aliases => '-s',
45
+ :desc => 'Serve with the given handler'
46
+ method_option :daemonize, :aliases => '-D',
47
+ :desc => 'Run daemonized in the background',
48
48
  :type => :boolean
49
- method_option :pid, :aliases => "-P",
50
- :desc => "File to store PID"
49
+ method_option :pid, :aliases => '-P',
50
+ :desc => 'File to store PID'
51
51
  def server
52
- require "rack"
52
+ require 'rack'
53
53
  Rack::Server.start rack_options
54
54
  end
55
55
  map %w(s rackup r) => :server
56
56
 
57
- desc "version", "Prints out the version"
57
+ desc 'version', 'Prints out the version'
58
58
  def version
59
59
  say VERSION
60
60
  end
@@ -66,10 +66,10 @@ module Machined
66
66
  @machined ||= Environment.new machined_options
67
67
  end
68
68
 
69
- # Returns the current environment, using the "RACK_ENV" variable
69
+ # Returns the current environment, using the 'RACK_ENV' variable
70
70
  # if set.
71
71
  def environment # :nodoc
72
- ENV["RACK_ENV"] || options["environment"]
72
+ ENV['RACK_ENV'] || options['environment']
73
73
  end
74
74
 
75
75
  # Returns the options needed for setting up
@@ -1,7 +1,7 @@
1
- require "padrino-helpers"
2
- require "rack"
3
- require "sprockets"
4
- require "sprockets-helpers"
1
+ require 'padrino-helpers'
2
+ require 'rack'
3
+ require 'sprockets'
4
+ require 'sprockets-helpers'
5
5
 
6
6
  module Machined
7
7
  class Context < Sprockets::Context
@@ -1,8 +1,9 @@
1
- require "ostruct"
2
- require "pathname"
3
- require "active_support/core_ext/hash/reverse_merge"
4
- require "crush"
5
- require "tilt"
1
+ require 'ostruct'
2
+ require 'pathname'
3
+ require 'active_support/cache'
4
+ require 'active_support/core_ext/hash/reverse_merge'
5
+ require 'crush'
6
+ require 'tilt'
6
7
 
7
8
  module Machined
8
9
  class Environment
@@ -11,24 +12,25 @@ module Machined
11
12
  # Default options for a Machined environment.
12
13
  DEFAULT_OPTIONS = {
13
14
  # Global configuration
14
- :root => ".",
15
- :config_path => "machined.rb",
16
- :output_path => "public",
17
- :environment => "development",
15
+ :root => '.',
16
+ :config_path => 'machined.rb',
17
+ :output_path => 'public',
18
+ :environment => 'development',
19
+ :cache => nil,
18
20
  :skip_bundle => false,
19
21
  :assets_only => false,
20
22
  :digest_assets => false,
21
23
  :gzip_assets => false,
22
- :layout => "application",
24
+ :layout => 'application',
23
25
 
24
26
  # Sprocket paths and URLs
25
- :assets_path => "assets",
27
+ :assets_path => 'assets',
26
28
  :assets_paths => %w(app/assets lib/assets vendor/assets),
27
- :assets_url => "/assets",
28
- :pages_path => "pages",
29
+ :assets_url => '/assets',
30
+ :pages_path => 'pages',
29
31
  :pages_paths => %w(app/pages),
30
- :pages_url => "/",
31
- :views_path => "views",
32
+ :pages_url => '/',
33
+ :views_path => 'views',
32
34
  :views_paths => %w(app/views),
33
35
 
34
36
  # Compression configuration
@@ -114,9 +116,10 @@ module Machined
114
116
  initializer :require_bundle do
115
117
  next if config.skip_bundle
116
118
 
117
- ENV["BUNDLE_GEMFILE"] ||= root.join("Gemfile").to_s
118
- if File.exist? ENV["BUNDLE_GEMFILE"]
119
- require "bundler"
119
+ ENV['BUNDLE_GEMFILE'] ||= root.join('Gemfile').to_s
120
+ if File.exist? ENV['BUNDLE_GEMFILE']
121
+ require 'bundler/setup'
122
+ require 'sprockets'
120
123
  Bundler.require :default, config.environment.to_sym
121
124
  end
122
125
  end
@@ -135,9 +138,9 @@ module Machined
135
138
  next if config.assets_only
136
139
 
137
140
  append_sprocket :pages do |pages|
138
- pages.register_mime_type "text/html", ".html"
139
- pages.register_preprocessor "text/html", Processors::FrontMatterProcessor
140
- pages.register_postprocessor "text/html", Processors::LayoutProcessor
141
+ pages.register_mime_type 'text/html', '.html'
142
+ pages.register_preprocessor 'text/html', Processors::FrontMatterProcessor
143
+ pages.register_postprocessor 'text/html', Processors::LayoutProcessor
141
144
  end
142
145
  end
143
146
 
@@ -147,7 +150,7 @@ module Machined
147
150
  # the layouts for the `pages` sprocket will be located here.
148
151
  initializer :create_views_sprocket do
149
152
  append_sprocket :views, :compile => false do |views|
150
- views.register_mime_type "text/html", ".html"
153
+ views.register_mime_type 'text/html', '.html'
151
154
  end
152
155
  end
153
156
 
@@ -172,6 +175,20 @@ module Machined
172
175
  end
173
176
  end
174
177
 
178
+ # Setup the global cache. Defaults to an in memory
179
+ # caching for development, and a file based cache for production.
180
+ initializer :configure_cache do
181
+ if config.cache.nil?
182
+ if config.environment == 'production'
183
+ config.cache = :file_store, 'tmp/cache'
184
+ else
185
+ config.cache = :memory_store
186
+ end
187
+ end
188
+
189
+ config.cache = ActiveSupport::Cache.lookup_store(*config.cache)
190
+ end
191
+
175
192
  # Do any configuration to the assets sprockets necessary
176
193
  # after the config file has been evaled.
177
194
  initializer :configure_assets_sprocket do
@@ -189,14 +206,17 @@ module Machined
189
206
  # Search for Rails Engines with assets and append those
190
207
  if defined? Rails::Engine
191
208
  Rails::Engine.subclasses.each do |engine|
192
- append_paths assets, engine.paths["app/assets"].existent_directories
193
- append_paths assets, engine.paths["lib/assets"].existent_directories
194
- append_paths assets, engine.paths["vendor/assets"].existent_directories
209
+ append_paths assets, engine.paths['app/assets'].existent_directories
210
+ append_paths assets, engine.paths['lib/assets'].existent_directories
211
+ append_paths assets, engine.paths['vendor/assets'].existent_directories
195
212
  end
196
213
  end
197
214
 
198
215
  # Setup the base URL for the assets (like the Rails asset_prefix)
199
216
  assets.config.url = config.assets_url
217
+
218
+ # Use the global cache store
219
+ assets.cache = config.cache
200
220
  end
201
221
 
202
222
  # Do any configuration to the pages sprockets necessary
@@ -210,6 +230,9 @@ module Machined
210
230
 
211
231
  # Setup the base URL for the pages
212
232
  pages.config.url = config.pages_url
233
+
234
+ # Use the global cache store
235
+ pages.cache = config.cache
213
236
  end
214
237
 
215
238
  # Do any configuration to the views sprockets necessary
@@ -220,6 +243,9 @@ module Machined
220
243
  # Append the configured views paths
221
244
  append_path views, config.views_path
222
245
  append_paths views, config.views_paths
246
+
247
+ # Use the global cache store
248
+ views.cache = config.cache
223
249
  end
224
250
 
225
251
  # Setup the JavaScript and CSS compressors
@@ -269,13 +295,13 @@ module Machined
269
295
  # and appends it to the #sprockets list. This will also create
270
296
  # an accessor with the given name that references the created sprocket.
271
297
  #
272
- # machined.append_sprocket :updates, :url => "/news" do |updates|
273
- # updates.append_path "updates"
298
+ # machined.append_sprocket :updates, :url => '/news' do |updates|
299
+ # updates.append_path 'updates'
274
300
  # end
275
301
  #
276
302
  # machined.updates # => #<Machined::Sprocket...>
277
- # machined.updates.config.url # => "/news"
278
- # machined.updates.paths # => [ ".../updates" ]
303
+ # machined.updates.config.url # => '/news'
304
+ # machined.updates.paths # => [ '.../updates' ]
279
305
  #
280
306
  def append_sprocket(name, options = {}, &block)
281
307
  create_sprocket(name, options, &block).tap do |sprocket|
@@ -388,7 +414,7 @@ module Machined
388
414
  JS_COMPRESSORS[config.js_compressor.to_sym]
389
415
  else
390
416
  Crush.register_js
391
- Tilt["js"]
417
+ Tilt['js']
392
418
  end
393
419
  end
394
420
 
@@ -403,7 +429,7 @@ module Machined
403
429
  CSS_COMPRESSORS[config.css_compressor.to_sym]
404
430
  else
405
431
  Crush.register_css
406
- Tilt["css"]
432
+ Tilt['css']
407
433
  end
408
434
  end
409
435
  end
@@ -6,11 +6,11 @@ module Machined
6
6
  def asset_path(source, options = {})
7
7
  case source
8
8
  when :css
9
- path_to_asset options, :dir => "stylesheets", :ext => "css"
9
+ path_to_asset options, :dir => 'stylesheets', :ext => 'css'
10
10
  when :images
11
- path_to_asset options, :dir => "images"
11
+ path_to_asset options, :dir => 'images'
12
12
  when :js
13
- path_to_asset options, :dir => "javascripts", :ext => "js"
13
+ path_to_asset options, :dir => 'javascripts', :ext => 'js'
14
14
  else
15
15
  path_to_asset source, options
16
16
  end
@@ -18,7 +18,7 @@ module Machined
18
18
 
19
19
  # Redefine image_path to work with Sprockets::Helpers.
20
20
  def image_path(source, options = {})
21
- asset_path source, { :dir => "images" }.merge(options)
21
+ asset_path source, { :dir => 'images' }.merge(options)
22
22
  end
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require "active_support/hash_with_indifferent_access"
1
+ require 'active_support/hash_with_indifferent_access'
2
2
 
3
3
  module Machined
4
4
  module Helpers
@@ -1,23 +1,20 @@
1
- require "active_support/memoizable"
2
- require "tilt"
1
+ require 'tilt'
3
2
 
4
3
  # We need to ensure that Tilt's ERB template uses
5
4
  # the same output variable that Padrino's helpers expect.
6
- Tilt::ERBTemplate.default_output_variable = "@_out_buf"
5
+ Tilt::ERBTemplate.default_output_variable = '@_out_buf'
7
6
 
8
7
  module Machined
9
8
  module Helpers
10
9
  module OutputHelpers
11
- extend ActiveSupport::Memoizable
12
-
13
10
  # A hash of Tilt templates that support
14
11
  # capture blocks where the key is the name
15
12
  # of the template.
16
13
  CAPTURE_ENGINES = {
17
- "Tilt::HamlTemplate" => :haml,
18
- "Tilt::ERBTemplate" => :erb,
19
- "Tilt::ErubisTemplate" => :erubis,
20
- "Slim::Template" => :slim
14
+ 'Tilt::HamlTemplate' => :haml,
15
+ 'Tilt::ERBTemplate' => :erb,
16
+ 'Tilt::ErubisTemplate' => :erubis,
17
+ 'Slim::Template' => :slim
21
18
  }
22
19
 
23
20
  protected
@@ -27,15 +24,18 @@ module Machined
27
24
  # Padrino's helpers to determine which type of template
28
25
  # engine to use when capturing blocks.
29
26
  def current_engine
30
- processors = environment.attributes_for(self.pathname).processors
31
- processors or return
32
- processors.each do |processor|
33
- engine = CAPTURE_ENGINES[processor.to_s] and return engine
27
+ unless defined?(@current_engine)
28
+ processors = environment.attributes_for(self.pathname).processors
29
+ processors.each do |processor|
30
+ if engine = CAPTURE_ENGINES[processor.to_s]
31
+ @current_engine = engine
32
+ break
33
+ end
34
+ end
34
35
  end
35
36
 
36
- nil
37
+ @current_engine
37
38
  end
38
- memoize :current_engine
39
39
  end
40
40
  end
41
41
  end