Permalink
Browse files

Made a start on the Loading of text_assets from fs to db, by extracti…

…ng name, minify and filter from filename in the load_file method.
  • Loading branch information...
1 parent c6f5428 commit 321fa79acfc1ba5d5a60dea21b74fc66181620a3 @nelstrom committed Nov 12, 2008
Showing with 41 additions and 2 deletions.
  1. +41 −1 lib/file_system/model/javascript_extensions.rb
  2. +0 −1 lib/file_system/model/stylesheet_extensions.rb
@@ -2,7 +2,6 @@ module FileSystem::Model::JavascriptExtensions
def self.included(base)
base.class_eval do
- puts "loading javascript extensions"
extend ClassMethods
end
end
@@ -13,6 +12,35 @@ def klass_name
end
end
+ def load_file(file)
+ # filename_regex = /^(?:(\d+)_)?([^.]+)(?:\.([\-\w]+))?/
+ # name, type_or_filter = $2, $3 if File.basename(file) =~ filename_regex
+ #
+ # basename = File.basename(file)
+ # name_parts = basename.count(".")
+ # filename_regex = /([^.]+)#{"(?:\.([^.]+))?" * name_parts}/
+ # if basename =~ filename_regex
+ # captures = Regexp.last_match.captures
+ # type_or_filter = captures.pop
+ # if captures[-1] == "min"
+ # min = true
+ # captures.pop
+ # end
+ # name = captures.join(".")
+ # end
+
+ 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?(:minifiy)
+ self.minifiy = mini
+ end
+ end
+
def filename
@filename ||= returning String.new do |output|
basename = self.name
@@ -38,5 +66,17 @@ def filename
def default_content_type
"js"
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
@@ -2,7 +2,6 @@ module FileSystem::Model::StylesheetExtensions
def self.included(base)
base.class_eval do
- puts "loading Stylesheet extensions"
extend ClassMethods
end
end

0 comments on commit 321fa79

Please sign in to comment.