module Stylish module Fs ExtensionsMap = { slim: ".html.slim", erb: ".html.erb", haml: ".html.haml", markdown: ".html.md", html: ".html", coffeescript: ".coffee", sass: ".sass", scss: ".scss", less: ".less", javascript: ".js", css: ".css" } extend ActiveSupport::Concern included do attribute :source_language, Symbol, :default => lambda {|model,attr| model.path && model.path.extname } attribute :contents, String end def save file_proxy.open("w+") do |fh| fh.write(persistable_contents) end end def filename (path_exists? ? path.basename : "#{ name }".parameterize + ".json") end def path_exists? path && path.exist? end def default_extension # TODO # Should we use Tilt::Template ExtensionsMap[source_language] end def persistable_contents contents end def contents orig = super.to_s orig.length > 0 ? orig : path.try(:read).to_s end # Eventually Could either be a GHFS::File or a normal File def file_proxy Pathname(path) end end end