diff --git a/app/controllers/admin/theme_assets_controller.rb b/app/controllers/admin/theme_assets_controller.rb
index 2ca7bd52..b6f4adac 100644
--- a/app/controllers/admin/theme_assets_controller.rb
+++ b/app/controllers/admin/theme_assets_controller.rb
@@ -4,6 +4,7 @@ module Admin
include ActionView::Helpers::SanitizeHelper
extend ActionView::Helpers::SanitizeHelper::ClassMethods
include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::NumberHelper
sections 'settings', 'theme_assets'
@@ -15,6 +16,7 @@ module Admin
@js_and_css_assets = (@assets[:javascripts] || []) + (@assets[:stylesheets] || [])
if request.xhr?
+ @images = @assets[:images]
render :action => 'images', :layout => false and return
else
@snippets = current_site.snippets.order_by([[:name, :asc]]).all.to_a
@@ -33,9 +35,10 @@ module Admin
success.json do
render :json => {
:status => 'success',
- :name => truncate(@theme_asset.slug, :length => 22),
- :slug => @theme_asset.slug,
- :url => @theme_asset.source.url
+ :url => @theme_asset.source.url,
+ :local_path => @theme_asset.local_path(true),
+ :size => number_to_human_size(@theme_asset.size),
+ :date => l(@theme_asset.updated_at, :format => :short)
}
end
failure.json { render :json => { :status => 'error' } }
diff --git a/app/models/theme_asset.rb b/app/models/theme_asset.rb
index dcd54148..14828fb6 100644
--- a/app/models/theme_asset.rb
+++ b/app/models/theme_asset.rb
@@ -49,6 +49,14 @@ class ThemeAsset
self.stylesheet? || self.javascript?
end
+ def local_path(short = false)
+ if short
+ self.read_attribute(:local_path).gsub(/^#{self.content_type.pluralize}\//, '')
+ else
+ self.read_attribute(:local_path)
+ end
+ end
+
def plain_text_name
if not @plain_text_name_changed
@plain_text_name ||= self.safe_source_filename
diff --git a/app/views/admin/theme_assets/_asset.html.haml b/app/views/admin/theme_assets/_asset.html.haml
index 320a436c..b6bee5ac 100644
--- a/app/views/admin/theme_assets/_asset.html.haml
+++ b/app/views/admin/theme_assets/_asset.html.haml
@@ -1,10 +1,13 @@
-%li{ :class => "#{'hidden' if asset.hidden?}" }
+- edit = local_assigns.key?(:edit) ? edit : true
+
+%li{ :class => "#{asset.new_record? ? 'new-asset' : 'asset'} #{'hidden' if asset.hidden?}" }
%em
- %strong= link_to asset.local_path, edit_admin_theme_asset_path(asset)
+ %strong= link_to asset.local_path(!edit), edit ? edit_admin_theme_asset_path(asset) : asset.source.url, :'data-local-path' => asset.local_path
.more
%span.size= number_to_human_size(asset.size)
—
%span!= t('.updated_at')
- = l asset.updated_at, :format => :short
+ %span.date= l asset.updated_at, :format => :short
- = link_to image_tag('admin/list/icons/trash.png'), admin_theme_asset_path(asset), :class => 'remove', :confirm => t('admin.messages.confirm'), :method => :delete
+ - if edit
+ = link_to image_tag('admin/list/icons/trash.png'), admin_theme_asset_path(asset), :class => 'remove', :confirm => t('admin.messages.confirm'), :method => :delete
diff --git a/app/views/admin/theme_assets/images.html.haml b/app/views/admin/theme_assets/images.html.haml
index 38c87747..24c0195a 100644
--- a/app/views/admin/theme_assets/images.html.haml
+++ b/app/views/admin/theme_assets/images.html.haml
@@ -4,12 +4,12 @@
.actions
= admin_button_tag t('admin.theme_assets.index.new'), admin_theme_assets_url(:json), :class => 'button small add', :id => 'upload-link'
- - if @image_assets.empty?
+ - if @images.empty?
%p.no-items!= t('.no_items')
- %ul.assets
- = render 'asset', :asset => current_site.theme_assets.build, :edit => false
+ %ul.list.theme-assets
+ = render 'asset', :asset => current_site.theme_assets.build(:updated_at => Time.now, :local_path => 'images/new.jpg', :content_type => 'image'), :edit => false
- = render :partial => 'asset', :collection => @image_assets, :locals => { :per_row => 3, :edit => false }
+ = render :partial => 'asset', :collection => @images, :locals => { :edit => false }
%li.clear
\ No newline at end of file
diff --git a/config/application.rb b/config/application.rb
index 95b268ee..88d63d5c 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -46,5 +46,8 @@ module Locomotive
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters << :password
+
+ config.middleware.insert_after ::ActionDispatch::Static, '::Locomotive::Middlewares::Fonts', :path => %r{^/fonts}
+ # config.middleware.insert_after 'Rack::Lock', 'Dragonfly::Middleware'
end
end
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 15590651..384d8225 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -4,14 +4,14 @@ Locomotive::Application.configure do
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
- config.cache_classes = false
+ config.cache_classes = true # false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
+ config.action_controller.perform_caching = true #false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
diff --git a/doc/TODO b/doc/TODO
index df047e55..48d55ea7 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -38,7 +38,8 @@ x snippet dependencies => do not work correctly
x mask internal asset_collections
x refactor ui for the theme assets page
x fix assets liquid tags / filters
-- proxy for fonts
+x upload and insert new images in a css or js from the ui is broken
+x proxy for fonts (http://markevans.github.com/dragonfly/file.Rails3.html)
- fix tests
- order yaml file (http://www.ruby-forum.com/topic/120295)
- global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating)
diff --git a/lib/locomotive.rb b/lib/locomotive.rb
index b08cb3f7..2ebf1499 100644
--- a/lib/locomotive.rb
+++ b/lib/locomotive.rb
@@ -1,4 +1,3 @@
-# require 'locomotive/patches'
require 'locomotive/configuration'
require 'locomotive/logger'
require 'locomotive/liquid'
@@ -14,6 +13,7 @@ require 'locomotive/regexps'
require 'locomotive/render'
require 'locomotive/import'
require 'locomotive/delayed_job'
+require 'locomotive/middlewares'
require 'mongo_session_store/mongoid'
diff --git a/lib/locomotive/liquid/filters/html.rb b/lib/locomotive/liquid/filters/html.rb
index 5aea887b..4673ac06 100644
--- a/lib/locomotive/liquid/filters/html.rb
+++ b/lib/locomotive/liquid/filters/html.rb
@@ -9,13 +9,17 @@ module Locomotive
return '' if input.nil?
unless input =~ /^(\/|http:)/
- stylesheet = ThemeAsset.new(:site => @context.registers[:site], :folder => 'stylesheets')
- input = '/' + ThemeAssetUploader.new(stylesheet).store_path(input)
+ segments = "stylesheets/#{input}".split('/')
+
+ filename, folder = segments.pop, segments.join('/')
+
+ stylesheet = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
+
+ input = '/' + ThemeAssetUploader.new(stylesheet).store_path(filename)
end
- # puts "stylesheet_tag context ? #{@context}"
-
input = "#{input}.css" unless input.ends_with?('.css')
+
%{}
end
@@ -25,20 +29,39 @@ module Locomotive
return '' if input.nil?
unless input =~ /^(\/|http:)/
- javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => 'javascripts')
- input = '/' + ThemeAssetUploader.new(javascript).store_path(input)
+ segments = "javascripts/#{input}".split('/')
+
+ filename, folder = segments.pop, segments.join('/')
+
+ javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
+
+ input = '/' + ThemeAssetUploader.new(javascript).store_path(filename)
end
input = "#{input}.js" unless input.ends_with?('.js')
+
%{}
end
+ def theme_image_url(input)
+ return '' if input.nil?
+
+ input = "images/#{input}" unless input.starts_with?('/')
+
+ segments = input.split('/')
+
+ filename, folder = segments.pop, segments.join('/')
+
+ image = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
+
+ '/' + ThemeAssetUploader.new(image).store_path(filename)
+ end
# Write an image tag
# input: url of the image OR asset drop
def image_tag(input, *args)
image_options = inline_options(args_to_options(args))
- ""
+ ""
end
# Embed a flash movie into a page
@@ -46,7 +69,7 @@ module Locomotive
# width: width (in pixel or in %) of the embedded movie
# height: height (in pixel or in %) of the embedded movie
def flash_tag(input, *args)
- path = get_path_from_asset(input)
+ path = get_url_from_asset(input)
embed_options = inline_options(args_to_options(args))
%{