added Dragonfly and WillPaginate + began to implement the submission of content entries thru a form
did
committed Jan 06, 2013
commit 6d090ef4b6e620e6a6123c5d8333f81002419a82
Showing 10
changed files with
147 additions
and 11 deletions
TODO
+6
-2
| @@ | @@ -2,21 +2,25 @@ |
| x templatized page | |
| x localized page | |
| + | x dragonfly |
| - listen: | |
| x content types and content entries / site | |
| - make it work for other platforms (linux, windows) | |
| + | - post content entry (WIP) |
| - I18n keys | |
| - liquid assigns: sessions (rack) | |
| - | - post content entry |
| - nice error page (replace the default exception middleware) to display: | |
| - liquid errors | |
| - other exceptions | |
| - nice logs | |
| - params to launch the thin server (port, address ?) | |
| + | - push: |
| + | - option to select to push only some parts (pages, ...etc) |
| + | - --force option |
| + | - static js/css assets (non coffeescript or sass files) are not reloaded if got changed. |
| - translations | |
| - | |
| - tests | |
| *** FEATURES *** | |
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 | |
| end | |
| end | |
locomotive/builder/liquid/drops/content_types.rb b/lib/locomotive/builder/liquid/drops/content_types.rb
+1
-1
| @@ | @@ -81,7 +81,7 @@ module Locomotive |
| conditions = @context['with_scope'].clone.delete_if { |k, _| %w(order_by per_page page).include?(k) } | |
| - | @content_type.contents.each do |content| |
| + | @content_type.entries.each do |content| |
| accepted = (conditions.map do |key, value| | |
| case value | |
| when TrueClass, FalseClass, String then content.send(key) == value | |
locomotive/builder/liquid/filters/resize.rb b/lib/locomotive/builder/liquid/filters/resize.rb
+1
-1
| @@ | @@ -5,7 +5,7 @@ module Locomotive |
| module Resize | |
| def resize(input, resize_string) | |
| - | Locomotive::Builder::DragonflyExt.resize_url(input, resize_string) |
| + | Locomotive::Builder::Dragonfly.instance.resize_url(input, resize_string) |
| end | |
| end | |
locomotive/builder/misc.rb b/lib/locomotive/builder/misc.rb
+3
-1
| @@ | @@ -1 +1,3 @@ |
| - | require 'locomotive/builder/misc/httparty.rb' |
| \ No newline at end of file | |
| + | require 'locomotive/builder/misc/will_paginate.rb' |
| + | require 'locomotive/builder/misc/httparty.rb' |
| + | require 'locomotive/builder/misc/dragonfly.rb' |
| \ No newline at end of file | |
locomotive/builder/misc/dragonfly.rb b/lib/locomotive/builder/misc/dragonfly.rb
+82
-0
| @@ | @@ -0,0 +1,82 @@ |
| + | module Locomotive |
| + | module Builder |
| + | class Dragonfly |
| + | |
| + | attr_accessor :path, :enabled |
| + | |
| + | def enabled? |
| + | !!self.enabled |
| + | end |
| + | |
| + | def resize_url(source, resize_string) |
| + | _source = (case source |
| + | when String then source |
| + | when Hash then source['url'] || source[:url] |
| + | else |
| + | source.try(:url) |
| + | end) |
| + | |
| + | if _source.blank? |
| + | LocomotiveEditor::Logger.error "Unable to resize on the fly: #{source.inspect}" |
| + | return |
| + | end |
| + | |
| + | return _source unless self.enabled? |
| + | |
| + | if _source =~ /^http/ |
| + | file = self.class.app.fetch_url(_source) |
| + | else |
| + | file = self.class.app.fetch_file(File.join(self.path, 'public', _source)) |
| + | end |
| + | |
| + | file.process(:thumb, resize_string).url |
| + | end |
| + | |
| + | def self.app |
| + | ::Dragonfly[:images] |
| + | end |
| + | |
| + | |
| + | def self.instance |
| + | @@instance ||= new |
| + | end |
| + | |
| + | def self.setup!(path) |
| + | self.instance.path = path |
| + | self.instance.enabled = false |
| + | |
| + | begin |
| + | require 'rack/cache' |
| + | require 'RMagick' |
| + | require 'dragonfly' |
| + | |
| + | ## initialize Dragonfly ## |
| + | app = ::Dragonfly[:images].configure_with(:imagemagick) |
| + | |
| + | ## configure it ## |
| + | ::Dragonfly[:images].configure do |c| |
| + | convert = `which convert`.strip.presence || '/usr/local/bin/convert' |
| + | c.convert_command = convert |
| + | c.identify_command = convert |
| + | |
| + | c.allow_fetch_url = true |
| + | c.allow_fetch_file = true |
| + | |
| + | c.url_format = '/images/dynamic/:job/:basename.:format' |
| + | end |
| + | |
| + | puts 'Dragonfly enabled' |
| + | |
| + | self.instance.enabled = true |
| + | rescue Exception => e |
| + | puts %{ |
| + | \tIf you want to take full benefits of all the features in the LocomotiveEditor, we recommend you to install ImageMagick and RMagick. |
| + | \tCheck out the documentation here: http://doc.locomotivecms.com/editor/installation.} |
| + | |
| + | puts 'Dragonfly disabled' |
| + | end |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/builder/misc/will_paginate.rb b/lib/locomotive/builder/misc/will_paginate.rb
+16
-0
| @@ | @@ -0,0 +1,16 @@ |
| + | require 'will_paginate' |
| + | require 'will_paginate/collection' |
| + | |
| + | Array.class_eval do |
| + | def paginate(options = {}) |
| + | raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options |
| + | |
| + | WillPaginate::Collection.create( |
| + | options[:page] || 1, |
| + | options[:per_page] || 30, |
| + | options[:total_entries] || self.length |
| + | ) { |pager| |
| + | pager.replace self[pager.offset, pager.per_page].to_a |
| + | } |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/builder/server.rb b/lib/locomotive/builder/server.rb
+9
-0
| @@ | @@ -1,9 +1,11 @@ |
| require 'rack/showexceptions' | |
| + | require 'coffee_script' |
| require 'locomotive/builder/listen' | |
| require 'locomotive/builder/server/middleware' | |
| require 'locomotive/builder/server/favicon' | |
| require 'locomotive/builder/server/dynamic_assets' | |
| + | require 'locomotive/builder/server/entry_submission' |
| require 'locomotive/builder/server/path' | |
| require 'locomotive/builder/server/locale' | |
| require 'locomotive/builder/server/page' | |
| @@ | @@ -18,6 +20,8 @@ module Locomotive::Builder |
| class Server | |
| def initialize(reader) | |
| + | Locomotive::Builder::Dragonfly.setup!(reader.mounting_point.path) |
| + | |
| @reader = reader | |
| @app = self.create_rack_app(@reader) | |
| @@ | @@ -36,10 +40,15 @@ module Locomotive::Builder |
| use Rack::ShowExceptions | |
| use Rack::Lint | |
| + | use EntrySubmission |
| + | |
| + | use ::Dragonfly::Middleware, :images |
| + | |
| use Rack::Static, { | |
| urls: ['/images', '/fonts', '/samples'], | |
| root: File.join(reader.mounting_point.path, 'public') | |
| } | |
| + | |
| use Favicon | |
| use DynamicAssets | |
| use Path | |
locomotive/builder/server/entry_submission.rb b/lib/locomotive/builder/server/entry_submission.rb
+25
-0
| @@ | @@ -0,0 +1,25 @@ |
| + | module Locomotive::Builder |
| + | class Server |
| + | |
| + | # Mimic the submission of a content entry |
| + | # |
| + | # |
| + | class EntrySubmission < Middleware |
| + | |
| + | def call(env) |
| + | self.set_accessors(env) |
| + | |
| + | if self.request.post? && self.path =~ /^entry_submissions\/(.*)/ |
| + | # TODO |
| + | [200, { 'Content-Type' => 'text/html' }, ['POST !!!']] |
| + | else |
| + | app.call(env) |
| + | end |
| + | end |
| + | |
| + | protected |
| + | |
| + | end |
| + | |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotive/builder/server/page.rb b/lib/locomotive/builder/server/page.rb
+3
-5
| @@ | @@ -17,17 +17,15 @@ module Locomotive::Builder |
| protected | |
| def set_page!(env) | |
| - | path = env['builder.path'] |
| - | |
| - | page = self.fetch_page(path) |
| + | page = self.fetch_page |
| puts "[Builder|Page] #{page.inspect}" | |
| env['builder.page'] = page | |
| end | |
| - | def fetch_page(path) |
| - | matchers = self.path_combinations(path) |
| + | def fetch_page |
| + | matchers = self.path_combinations(self.path) |
| self.mounting_point.pages.values.detect do |_page| | |
| matchers.include?(_page.safe_fullpath) || | |