templatized pages (wip) + listen site changes (wip)
did
committed Jan 01, 2013
commit 6e2368a469bd3f552e6c2e00887f8247757737bc
Showing 8
changed files with
86 additions
and 6 deletions
Gemfile
+4
-2
| @@ | @@ -1,6 +1,8 @@ |
| source 'https://rubygems.org' | |
| - | # Specify your gem's dependencies in steam.gemspec |
| + | # Specify your gem's dependencies in builder.gemspec |
| gemspec | |
| - | gem 'locomotivecms_mounter', path: '../gems/mounter' |
| \ No newline at end of file | |
| + | gem 'locomotivecms_mounter', path: '../gems/mounter' |
| + | |
| + | gem 'rb-fsevent', '~> 0.9.1' |
| \ No newline at end of file | |
TODO
+21
-0
| @@ | @@ -0,0 +1,21 @@ |
| + | *** REQUIREMENTS *** |
| + | |
| + | - templatized page |
| + | - nice error page (replace the default exception middleware) to display: |
| + | - liquid errors |
| + | - other exceptions |
| + | - nice logs |
| + | - params to setup the server |
| + | - sessions |
| + | - post content entry |
| + | - listen: |
| + | - make it work for external libs |
| + | - better installation for all the platforms |
| + | |
| + | - tests |
| + | |
| + | *** FEATURES *** |
| + | |
| + | - toolbar to: |
| + | - push a whole site / page(s) / snippet(s) / .... |
| + | - create / update a content type |
locomotive/builder/cli.rb b/lib/locomotive/builder/cli.rb
+1
-1
| @@ | @@ -23,7 +23,7 @@ module Locomotive |
| reader.run!(path: path) | |
| server = Thin::Server.new('0.0.0.0', port, Locomotive::Builder::Server.new(reader)) | |
| - | server.threaded = true |
| + | # server.threaded = true |
| server.start | |
| # TODO: To be removed | |
locomotive/builder/server.rb b/lib/locomotive/builder/server.rb
+17
-0
| @@ | @@ -1,10 +1,13 @@ |
| require 'rack/showexceptions' | |
| + | require 'listen' |
| + | |
| require 'locomotive/builder/server/middleware' | |
| require 'locomotive/builder/server/favicon' | |
| require 'locomotive/builder/server/dynamic_assets' | |
| require 'locomotive/builder/server/path' | |
| require 'locomotive/builder/server/locale' | |
| require 'locomotive/builder/server/page' | |
| + | require 'locomotive/builder/server/templatized_page' |
| require 'locomotive/builder/server/not_found' | |
| require 'locomotive/builder/server/renderer' | |
| @@ | @@ -15,6 +18,8 @@ module Locomotive::Builder |
| class Server | |
| def initialize(reader) | |
| + | # puts Dir[File.join(reader.mounting_point.path, 'app/**/*.liquid*')].inspect |
| + | |
| @reader = reader | |
| @app = Rack::Builder.new do | |
| use Rack::ShowExceptions | |
| @@ | @@ -29,11 +34,23 @@ module Locomotive::Builder |
| use Path | |
| use Locale | |
| use Page | |
| + | use TemplatizedPage |
| use NotFound | |
| use Renderer | |
| run Renderer.new | |
| end | |
| + | |
| + | # TODO: refactor it by moving it into another place |
| + | pages_reloader = Proc.new do |modified, added, removed| |
| + | reader.reload(:pages) |
| + | end |
| + | |
| + | listener = Listen.to(File.join(reader.mounting_point.path, 'app/views/pages')) |
| + | .filter(/\.liquid/) |
| + | .change(&pages_reloader) |
| + | |
| + | listener.start(false) |
| end | |
| def call(env) | |
locomotive/builder/server/middleware.rb b/lib/locomotive/builder/server/middleware.rb
+2
-1
| @@ | @@ -5,7 +5,7 @@ module Locomotive::Builder |
| attr_accessor :app, :request | |
| - | attr_accessor :mounting_point, :page |
| + | attr_accessor :mounting_point, :page, :content_entry |
| def initialize(app = nil) | |
| @app = app | |
| @@ | @@ -21,6 +21,7 @@ module Locomotive::Builder |
| self.request = Rack::Request.new(env) | |
| self.mounting_point = env['builder.mounting_point'] | |
| self.page = env['builder.page'] | |
| + | self.content_entry = env['builder.content_entry'] |
| end | |
| def site | |
locomotive/builder/server/renderer.rb b/lib/locomotive/builder/server/renderer.rb
+7
-2
| @@ | @@ -47,12 +47,17 @@ module Locomotive::Builder |
| def locomotive_context(other_assigns = {}) | |
| assigns = self.locomotive_default_assigns | |
| - | # process data from the session |
| + | # TODO: process data from the session |
| # assigns.merge!(self.locomotive_flash_assigns) | |
| assigns.merge!(other_assigns) | |
| - | # TODO: templatized page |
| + | # templatized page |
| + | if self.page && self.content_entry |
| + | ['content_entry', 'entry', self.page.content_type.slug.singularize].each do |key| |
| + | assigns[key] = self.content_entry |
| + | end |
| + | end |
| # if defined?(self.page) && self.page.templatized? # add instance from content type | |
| # content_entry = self.page.content_entry.to_liquid | |
locomotive/builder/server/templatized_page.rb b/lib/locomotive/builder/server/templatized_page.rb
+32
-0
| @@ | @@ -0,0 +1,32 @@ |
| + | module Locomotive::Builder |
| + | class Server |
| + | |
| + | class TemplatizedPage < Middleware |
| + | |
| + | def call(env) |
| + | self.set_accessors(env) |
| + | |
| + | if self.page && self.page.templatized? |
| + | self.set_content_entry!(env) |
| + | end |
| + | |
| + | app.call(env) |
| + | end |
| + | |
| + | protected |
| + | |
| + | def set_content_entry!(env) |
| + | %r(^#{self.page.safe_fullpath.gsub('*', '([^\/]+)')}$) =~ self.path |
| + | |
| + | permalink = $1 |
| + | |
| + | if content_entry = self.page.content_type.find_entry(permalink) |
| + | env['builder.content_entry'] = content_entry |
| + | else |
| + | env['builder.page'] = nil |
| + | end |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotivecms_builder.gemspec
+2
-0
| @@ | @@ -25,6 +25,8 @@ Gem::Specification.new do |gem| |
| gem.add_dependency 'dragonfly', '~> 0.9.12' | |
| gem.add_dependency 'rack-cache', '~> 1.1' | |
| gem.add_dependency 'rack-rescue', '~> 0.1.2' | |
| + | gem.add_dependency 'listen', '~> 0.7.0' |
| + | # gerb-fsevent |
| gem.add_dependency 'rmagick', '2.12.2' | |
| gem.add_dependency 'httmultiparty', '~> 0.3.8' | |
| gem.add_dependency 'will_paginate', '~> 3.0.3' | |