bugs when accessign assets from asset collections in templates + uploader for custom fields was buggy

This commit is contained in:
dinedine 2010-10-11 01:16:43 +02:00
parent 32f8351889
commit 86ac74e290
10 changed files with 43 additions and 27 deletions

View File

@ -32,6 +32,10 @@ class Asset
end end
end end
def site_id # needed by the uploader of custom fields
self.collection.site_id
end
def to_liquid def to_liquid
Locomotive::Liquid::Drops::Asset.new(self) Locomotive::Liquid::Drops::Asset.new(self)
end end

View File

@ -29,6 +29,10 @@ class ContentInstance
alias :visible? :_visible? alias :visible? :_visible?
def site_id # needed by the uploader of custom fields
self.content_type.site_id
end
def visible? def visible?
self._visible || self._visible.nil? self._visible || self._visible.nil?
end end

View File

@ -27,11 +27,10 @@ class AssetUploader < CarrierWave::Uploader::Base
process :convert => 'png' process :convert => 'png'
end end
process :set_content_type
process :set_size
process :set_width_and_height process :set_width_and_height
after :cache, :set_size
after :cache, :set_content_type
def set_content_type(*args) def set_content_type(*args)
value = :other value = :other

View File

@ -1,13 +0,0 @@
# encoding: utf-8
class FontUploader < CarrierWave::Uploader::Base
def store_dir
"sites/#{model.id}/theme/fonts"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end

View File

@ -30,14 +30,16 @@ x snippet dependencies => do not work correctly
x exceptions x exceptions
x page to import theme x page to import theme
x contents: group_by, oder_by, api_enabled x contents: group_by, oder_by, api_enabled
? asset collections x folders for theme assets
? fonts x theme assets whitelist
? folders for theme assets x fonts
? theme assets whitelist x asset collections
- add samples ? - add samples ?
x mask internal asset_collections x mask internal asset_collections
- refactor ui for the theme assets page x refactor ui for the theme assets page
x fix assets liquid tags / filters
- proxy for fonts - proxy for fonts
- fix tests
- order yaml file (http://www.ruby-forum.com/topic/120295) - order yaml file (http://www.ruby-forum.com/topic/120295)
- global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating) - global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating)
- write my first tutorial about locomotive - write my first tutorial about locomotive

View File

@ -5,7 +5,8 @@ module CustomFields
class FileUploader < ::CarrierWave::Uploader::Base class FileUploader < ::CarrierWave::Uploader::Base
def store_dir def store_dir
"sites/#{model.content_type.site_id}/contents/#{model.id}/files" puts
"sites/#{model.site_id}/contents/#{model.class.model_name.underscore}/#{model.id}/files"
end end
def cache_dir def cache_dir

View File

@ -11,6 +11,10 @@ module Locomotive
end end
end end
def url
@source.source.url
end
end end
end end
end end

View File

@ -5,13 +5,13 @@ module Locomotive
class AssetCollections < ::Liquid::Drop class AssetCollections < ::Liquid::Drop
def before_method(meth) def before_method(meth)
collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s) collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s).first
AssetCollection.new(collection) AssetCollectionProxy.new(collection)
end end
end end
class AssetCollection < ::Liquid::Drop class AssetCollectionProxy < ::Liquid::Drop
def initialize(collection) def initialize(collection)
@collection = collection @collection = collection

View File

@ -6,9 +6,10 @@ module Locomotive
class Base < ::Liquid::Drop class Base < ::Liquid::Drop
def before_method(meth) def before_method(meth)
content_type = self.class.name.demodulize.underscore.singularize content_type = self.class.name.demodulize.underscore #.singularize
asset = ThemeAsset.new(:site => @context.registers[:site], :folder => content_type)
asset = ThemeAsset.new(:site => @context.registers[:site], :content_type => content_type)
'/' + ThemeAssetUploader.new(asset).store_path(meth.gsub('__', '.')) '/' + ThemeAssetUploader.new(asset).store_path(meth.gsub('__', '.'))
end end

View File

@ -7,6 +7,14 @@ module Locomotive
# input: url of the css file # input: url of the css file
def stylesheet_tag(input) def stylesheet_tag(input)
return '' if input.nil? return '' if input.nil?
unless input =~ /^(\/|http:)/
stylesheet = ThemeAsset.new(:site => @context.registers[:site], :folder => 'stylesheets')
input = '/' + ThemeAssetUploader.new(stylesheet).store_path(input)
end
# puts "stylesheet_tag context ? #{@context}"
input = "#{input}.css" unless input.ends_with?('.css') input = "#{input}.css" unless input.ends_with?('.css')
%{<link href="#{input}" media="screen" rel="stylesheet" type="text/css" />} %{<link href="#{input}" media="screen" rel="stylesheet" type="text/css" />}
end end
@ -15,6 +23,12 @@ module Locomotive
# input: url of the javascript file # input: url of the javascript file
def javascript_tag(input) def javascript_tag(input)
return '' if input.nil? return '' if input.nil?
unless input =~ /^(\/|http:)/
javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => 'javascripts')
input = '/' + ThemeAssetUploader.new(javascript).store_path(input)
end
input = "#{input}.js" unless input.ends_with?('.js') input = "#{input}.js" unless input.ends_with?('.js')
%{<script src="#{input}" type="text/javascript"></script>} %{<script src="#{input}" type="text/javascript"></script>}
end end