class Glug::Stylesheet

—– Stylesheet

the main document object

Attributes

base_dir[RW]
kv[RW]
params[RW]
refs[RW]
sources[RW]

Public Class Methods

new(base_dir: nil, params: nil, &block) click to toggle source
# File lib/glug/stylesheet.rb, line 9
def initialize(base_dir: nil, params: nil, &block)
        @sources = {}
        @kv = {}
        @layers = []
        @refs = {}
        @base_dir = base_dir || ''
        @params = params || {}
        instance_eval(&block)
end

Public Instance Methods

_add_layer(layer) click to toggle source

Setter for Layer to add sublayers

# File lib/glug/stylesheet.rb, line 48
def _add_layer(layer)
        @layers << layer
end
include_file(fn) click to toggle source

Load file

# File lib/glug/stylesheet.rb, line 53
def include_file(fn)
        instance_eval(File.read(File.join(@base_dir, fn)))
end
layer(id, opts={}, &block) click to toggle source

Add a layer creates a new Layer object using the block supplied

# File lib/glug/stylesheet.rb, line 31
def layer(id, opts={}, &block)
        r = Layer.new(self, :id=>id, :kv=>opts)
        @layers << r
        r.instance_eval(&block)
end
method_missing(method_sym, *arguments) click to toggle source

Set a property, e.g. ‘bearing 29’

# File lib/glug/stylesheet.rb, line 20
def method_missing(method_sym, *arguments)
        @kv[method_sym] = arguments[0]
end
source(source_name, opts={}) click to toggle source

Add a source

# File lib/glug/stylesheet.rb, line 25
def source(source_name, opts={})
        @sources[source_name] = opts
end
to_hash() click to toggle source

Assemble into GL JSON format

# File lib/glug/stylesheet.rb, line 38
def to_hash
        out = @kv.dup
        out['sources'] = @sources.dup
        out['sources'].each { |k,v| v.delete(:default); out['sources'][k] = v }
        out['layers'] = @layers.select { |r| r.write? }.collect { |r| r.to_hash }.compact
        out
end
to_json(*args) click to toggle source
# File lib/glug/stylesheet.rb, line 45
def to_json(*args); JSON.neat_generate(to_hash) end