class Glug::Stylesheet
—– Stylesheet
the main document object
Attributes
kv[RW]
refs[RW]
sources[RW]
Public Class Methods
new(&block)
click to toggle source
# File lib/glug.rb, line 66 def initialize(&block) @sources = {} @kv = {} @layers = [] @refs = {} instance_eval(&block) end
Public Instance Methods
_add_layer(layer)
click to toggle source
Setter for Layer
to add sublayers
# File lib/glug.rb, line 103 def _add_layer(layer) @layers << layer end
layer(id, opts={}, &block)
click to toggle source
Add a layer creates a new Layer
object using the block supplied
# File lib/glug.rb, line 86 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.rb, line 75 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.rb, line 80 def source(source_name, opts={}) @sources[source_name] = opts end
to_hash()
click to toggle source
Assemble into Mapbox GL JSON format
# File lib/glug.rb, line 93 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.rb, line 100 def to_json(*args); JSON.neat_generate(to_hash) end