diff --git a/app/models/asset.rb b/app/models/asset.rb
index 84f321d1..763f8aba 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -32,6 +32,10 @@ class Asset
end
end
+ def site_id # needed by the uploader of custom fields
+ self.collection.site_id
+ end
+
def to_liquid
Locomotive::Liquid::Drops::Asset.new(self)
end
diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb
index d92d8669..37148bae 100644
--- a/app/models/content_instance.rb
+++ b/app/models/content_instance.rb
@@ -29,6 +29,10 @@ class ContentInstance
alias :visible? :_visible?
+ def site_id # needed by the uploader of custom fields
+ self.content_type.site_id
+ end
+
def visible?
self._visible || self._visible.nil?
end
diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb
index baad1077..57ec81fc 100644
--- a/app/uploaders/asset_uploader.rb
+++ b/app/uploaders/asset_uploader.rb
@@ -27,11 +27,10 @@ class AssetUploader < CarrierWave::Uploader::Base
process :convert => 'png'
end
+ process :set_content_type
+ process :set_size
process :set_width_and_height
- after :cache, :set_size
- after :cache, :set_content_type
-
def set_content_type(*args)
value = :other
diff --git a/app/uploaders/font_uploader.rb b/app/uploaders/font_uploader.rb
deleted file mode 100644
index 40fdd4d2..00000000
--- a/app/uploaders/font_uploader.rb
+++ /dev/null
@@ -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
diff --git a/doc/TODO b/doc/TODO
index 8cd74651..df047e55 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -30,14 +30,16 @@ x snippet dependencies => do not work correctly
x exceptions
x page to import theme
x contents: group_by, oder_by, api_enabled
- ? asset collections
- ? fonts
- ? folders for theme assets
- ? theme assets whitelist
+ x folders for theme assets
+ x theme assets whitelist
+ x fonts
+ x asset collections
- add samples ?
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
+- 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)
- write my first tutorial about locomotive
diff --git a/lib/locomotive/custom_fields.rb b/lib/locomotive/custom_fields.rb
index f29f7447..836b2102 100644
--- a/lib/locomotive/custom_fields.rb
+++ b/lib/locomotive/custom_fields.rb
@@ -5,7 +5,8 @@ module CustomFields
class FileUploader < ::CarrierWave::Uploader::Base
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
def cache_dir
diff --git a/lib/locomotive/liquid/drops/asset.rb b/lib/locomotive/liquid/drops/asset.rb
index 0bf8ed74..5049721d 100644
--- a/lib/locomotive/liquid/drops/asset.rb
+++ b/lib/locomotive/liquid/drops/asset.rb
@@ -11,6 +11,10 @@ module Locomotive
end
end
+ def url
+ @source.source.url
+ end
+
end
end
end
diff --git a/lib/locomotive/liquid/drops/asset_collections.rb b/lib/locomotive/liquid/drops/asset_collections.rb
index 212c38a9..f822a73c 100644
--- a/lib/locomotive/liquid/drops/asset_collections.rb
+++ b/lib/locomotive/liquid/drops/asset_collections.rb
@@ -5,13 +5,13 @@ module Locomotive
class AssetCollections < ::Liquid::Drop
def before_method(meth)
- collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s)
- AssetCollection.new(collection)
+ collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s).first
+ AssetCollectionProxy.new(collection)
end
end
- class AssetCollection < ::Liquid::Drop
+ class AssetCollectionProxy < ::Liquid::Drop
def initialize(collection)
@collection = collection
diff --git a/lib/locomotive/liquid/drops/theme_assets.rb b/lib/locomotive/liquid/drops/theme_assets.rb
index b69c173b..218663bb 100644
--- a/lib/locomotive/liquid/drops/theme_assets.rb
+++ b/lib/locomotive/liquid/drops/theme_assets.rb
@@ -6,9 +6,10 @@ module Locomotive
class Base < ::Liquid::Drop
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('__', '.'))
end
diff --git a/lib/locomotive/liquid/filters/html.rb b/lib/locomotive/liquid/filters/html.rb
index 881a4a35..5aea887b 100644
--- a/lib/locomotive/liquid/filters/html.rb
+++ b/lib/locomotive/liquid/filters/html.rb
@@ -7,6 +7,14 @@ module Locomotive
# input: url of the css file
def stylesheet_tag(input)
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')
%{}
end
@@ -15,6 +23,12 @@ module Locomotive
# input: url of the javascript file
def javascript_tag(input)
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')
%{}
end