Module: Cytoplasm
- Defined in:
- lib/cytoplasm.rb,
lib/cytoplasm/ajax.rb,
lib/cytoplasm/railtie.rb,
lib/cytoplasm/version.rb,
app/controllers/cytoplasm/dash_controller.rb,
app/controllers/cytoplasm/fonts_controller.rb,
app/controllers/cytoplasm/settings_controller.rb,
app/controllers/cytoplasm/performance_controller.rb,
app/controllers/cytoplasm/transitions_controller.rb
Defined Under Namespace
Modules: Rails
Classes: Ajax, DashController, FontsController, PerformanceController, Railtie, SettingsController, TransitionsController
Constant Summary
collapse
- VERSION =
"0.4.5"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.addClass(options, newclasses) ⇒ Object
344
345
346
347
348
349
|
# File 'lib/cytoplasm.rb', line 344
def self.addClass(options,newclasses)
options[:class] ||= ""
newclasses = [newclasses] if newclasses.is_a? String
newclasses.each_with_index {|c,i| options[:class] += ((i>0)?" ":"")+c.to_s}
return options
end
|
.create_path_unless_exists(path) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/cytoplasm.rb', line 210
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
|
.css ⇒ Object
282
283
284
|
# File 'lib/cytoplasm.rb', line 282
def self.css()
return dependencies("css")
end
|
.defaults(which = nil, value = nil) ⇒ Object
258
259
260
|
# File 'lib/cytoplasm.rb', line 258
def self.defaults(which=nil,value=nil)
traverse_hash(@defaults,which,value)
end
|
.dependencies(type = "*") ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/cytoplasm.rb', line 263
def self.dependencies(type="*")
deps = []
valid_types = ["*","css","js"]
return false unless valid_types.include? type
case type
when "*"
valid_types.each {|t| dependencies(t).each {|d| deps << d} if t!="*"}
when "css"
deps << "http://ajax.googleapis.com/ajax/libs/jqueryui/"+vars("setup.jqueryui.version")+"/themes/"+vars("setup.jqueryui.theme")+"/jquery-ui.css"
deps += load_fonts()
@dependencies[:css].each {|stylesheet| deps << "cytoplasm/"+stylesheet}
when "js"
@dependencies[:js].each {|plugin| deps << "cytoplasm/"+plugin}
end
return deps
end
|
.deps(type = "*") ⇒ Object
279
280
281
|
# File 'lib/cytoplasm.rb', line 279
def self.deps(type="*")
return dependencies(type)
end
|
.generate_uid ⇒ Object
336
337
338
|
# File 'lib/cytoplasm.rb', line 336
def self.generate_uid
(0...50).map{('a'..'z').to_a[rand(26)]}.join
end
|
.hash_to_css(k, v, parent = "") ⇒ Object
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/cytoplasm.rb', line 289
def self.hash_to_css(k,v,parent="")
output = ""
if v.is_a? Hash
parent += "#{k}_"
v.each {|kk,vv| output += hash_to_css(kk,vv,parent)}
return output
else
k = k.to_s
v = v.to_s
output = ""
output += "@#{parent}#{k}:#{v};\n"
if k == "background" and v.starts_with? "linear-gradient"
args = v[16..-2].split(/,\s*/)
direction = args.shift
args = direction+", "+args.reverse().join(", ")
output += "@#{parent}#{k}_reverse:linear-gradient(#{args});\n"
end
return output
end
end
|
.js ⇒ Object
285
286
287
|
# File 'lib/cytoplasm.rb', line 285
def self.js()
return dependencies("js")
end
|
.load_fonts ⇒ Object
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/cytoplasm.rb', line 310
def self.load_fonts
sheets = []
enabled = {}
begin
enabled = YAML::load_file("public/fonts/enabled.yml")
rescue
puts "Failed to parse YAML in public/fonts/enabled.yml!"
end
if enabled.is_a? Hash and enabled.any?
enabled.each do |dir,fonts|
if fonts.is_a? Hash and fonts.any?
fonts.each do |fam,variants|
if dir == "fontsquirrel"
sheets << "/fonts/"+fam+"/stylesheet.css"
elsif dir == "googlewebfonts"
sheet = "http://fonts.googleapis.com/css?family="+fam
sheet += ":" + variants.join(",") if variants.any?
sheets << sheet
end
end
end
end
end
return sheets
end
|
.load_vars(opts = {}) ⇒ Object
176
177
178
179
|
# File 'lib/cytoplasm.rb', line 176
def self.load_vars(opts={})
@vars = @defaults
@vars.deep_merge!(opts_to_sym(opts))
end
|
.load_vars_from(path_to_yaml_file) ⇒ Object
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/cytoplasm.rb', line 188
def self.load_vars_from(path_to_yaml_file)
begin
vars = YAML::load(IO.read(path_to_yaml_file))
rescue Errno::ENOENT
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)
end
|
.opts_to_sym(opts) ⇒ Object
181
182
183
184
185
186
|
# File 'lib/cytoplasm.rb', line 181
def self.opts_to_sym(opts)
fixed = {}
return opts unless opts.is_a? Hash
opts.each {|k,v| fixed[k.to_sym] = ((v.is_a?(Hash)) ? opts_to_sym(v) : v)}
return fixed
end
|
.precompile_styles(styles) ⇒ Object
205
206
207
208
|
# File 'lib/cytoplasm.rb', line 205
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
|
.save_config(opts = {}) ⇒ Object
199
200
201
202
203
|
# File 'lib/cytoplasm.rb', line 199
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
|
.traverse_hash(hash, which = nil, value = nil) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/cytoplasm.rb', line 227
def self.traverse_hash(hash,which=nil,value=nil)
return hash if which.nil?
if which.is_a? String and which.include? '.'
returnvar = hash
levels = []
which.split(".").each do |level|
levels << level
returnvar = returnvar[level.to_sym] unless returnvar[level.to_sym].nil?
end
else
returnvar = hash[which.to_sym]
end
unless returnvar.nil?
if value.nil?
return returnvar.to_s
else
if which.include? "."
else
hash[which.to_sym] = value
end
end
end
end
|
.variable(which = nil, value = nil) ⇒ Object
252
253
254
|
# File 'lib/cytoplasm.rb', line 252
def self.variable(which=nil,value=nil)
traverse_hash(@vars,which,value)
end
|
.vars(which = nil, value = nil) ⇒ Object
255
256
257
|
# File 'lib/cytoplasm.rb', line 255
def self.vars(which=nil,value=nil)
variable(which,value)
end
|
Instance Method Details
#index ⇒ Object
340
341
342
|
# File 'lib/cytoplasm.rb', line 340
def index
end
|
#initialize ⇒ Object
172
173
174
|
# File 'lib/cytoplasm.rb', line 172
def initialize
load_vars_from("config/cytoplasm-config.yml")
end
|