Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TextAssetExtensions now looks much like StylesheetExtensions. When lo…

…ading extra models into FileSystem::MODELS, TextAsset comes before Sytlesheet and Javascript.
  • Loading branch information...
commit 4f54c79477ca52cbd961eeb68b00fd9070e9b46c 1 parent a9498de
@nelstrom authored
View
67 lib/file_system/model/text_asset_extensions.rb
@@ -1,5 +1,54 @@
module FileSystem::Model::TextAssetExtensions
+ def self.included(base)
+ base.class_eval do
+ extend ClassMethods
+ end
+ end
+
+ module ClassMethods
+ def klass_name
+ "TextAsset"
+ end
+
+ def load_files
+ files = Dir[path + "/**"]
+ unless files.blank?
+ records_on_filesystem = []
+ files.each do |file|
+ record = find_or_initialize_by_filename(File.basename(file))
+ puts "Loading #{self.name.downcase} from #{File.basename(file)}"
+ record.load_file(file)
+ record.save
+ records_on_filesystem << record
+ end
+ fileless_db_records = records_on_database - records_on_filesystem
+ fileless_db_records.each { |item| delete_record(item) }
+ end
+ end
+
+
+ def extract_name(basename)
+ name_parts = basename.split(".")
+ type_or_filter = name_parts.pop
+ name_parts.pop if name_parts[-1] == "min"
+ name = name_parts.join(".")
+ end
+ end
+
+ def load_file(file)
+ name, mini, type_or_filter = extract_attrs_from_filename(File.basename(file))
+ content = open(file).read
+ self.name = name
+ self.content = content
+ if respond_to?(:filter_id)
+ self.filter_id = filters.include?(type_or_filter) ? type_or_filter.camelize : nil
+ end
+ if respond_to?(:minify)
+ self.minify = mini
+ end
+ end
+
def filename
@filename ||= returning String.new do |output|
basename = self.name
@@ -20,4 +69,22 @@ def filename
[basename, minify, extension].compact.join("."))
end
end
+
+ private
+ def default_content_type
+ super
+ end
+
+ def extract_attrs_from_filename(basename)
+ name_parts = basename.split(".")
+ type_or_filter = name_parts.pop
+ mini = false
+ if name_parts[-1] == "min"
+ mini = true
+ name_parts.pop
+ end
+ name = name_parts.join(".")
+ [name, mini, type_or_filter]
+ end
+
end
View
4 sns_extension.rb
@@ -38,7 +38,9 @@ class SnsExtension < Radiant::Extension
def activate
begin
- FileSystem::MODELS << "Javascript" << "Stylesheet"
+ # FileSystem::MODELS << "Javascript" << "Stylesheet"
+ # FileSystem::MODELS << "TextAsset"
+ FileSystem::MODELS << "TextAsset" << "Javascript" << "Stylesheet"
rescue NameError, LoadError
end
admin.tabs.add "CSS", "/admin/css", :after => "Layouts", :visibility => [:admin, :developer]
Please sign in to comment.
Something went wrong with that request. Please try again.