lib/cytoplasm.rb in cytoplasm-0.3.1 vs lib/cytoplasm.rb in cytoplasm-0.3.3
- old
+ new
@@ -173,19 +173,39 @@
puts "YAML configuration file couldn't be found. Using defaults."; return
rescue Psych::SyntaxError
puts "YAML configuration file contains invalid syntax. Using defaults."; return
end
load_vars(vars)
- compile_css()
end
def self.save_config(opts={})
puts "SAVING CONFIGURATION FILE"
load_vars(opts)
File.open("config/cytoplasm-config.yml", 'w+') {|f| f.write(@vars.to_yaml) }
end
+ def self.precompile_styles(styles)
+ puts "PRECOMPILING CSS TO FILE"
+ File.open(create_path_unless_exists("public/css")+"/cytoplasm-styles.css", 'w+') {|f| f.write(styles)} if styles.is_a? String and styles!=""
+ end
+
+ def self.create_path_unless_exists(path)
+ unless File.exists?(path)
+ count = 0
+ path.split("/").each do |dir|
+ Dir.mkdir(dir) unless File.exists?(dir)
+ Dir.chdir(dir)
+ count += 1
+ end
+ while count > 0 do
+ Dir.chdir("../")
+ count -= 1
+ end
+ end
+ return path
+ end
+
# Getters and setters
def self.traverse_hash(hash,which=nil,value=nil)
return hash if which.nil?
if which.is_a? String and which.include? '.'
returnvar = hash
@@ -243,24 +263,9 @@
def self.css()
return dependencies("css")
end
def self.js()
return dependencies("js")
- end
- def self.compile_css()
- varfile = ::Rails.root+"public/cytoplasm/cytoplasm.vars.less"
- # Check for varfile, create one if it doesn't exist
- unless File.exists?("public/cytoplasm")
- Dir.chdir("public")
- Dir.mkdir("cytoplasm")
- Dir.chdir("../")
- end
-
- File.open(varfile,"wb") do |f|
- css = ""
- @vars.each {|k,v| css += hash_to_css(k,v)}
- f.write(css)
- end
end
def self.hash_to_css(k,v,parent="")
output = ""
if v.is_a? Hash
\ No newline at end of file