Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/glug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ module Glug # :nodoc:
require_relative 'glug/stylesheet'
require_relative 'glug/layer'
require_relative 'glug/extensions'
require_relative 'glug/stylesheet_dsl'
12 changes: 4 additions & 8 deletions lib/glug/stylesheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ def initialize(base_dir: nil, params: nil, &block)
@layers = []
@base_dir = base_dir || ''
@params = params || {}
instance_eval(&block)
end

# Arbitrary properties can be defined, e.g. "foo :bar" results in a top-level "foo":"bar" in the style
def respond_to_missing?(*)
true
@dsl = StylesheetDSL.new(self)
@dsl.instance_eval(&block)
end

# Set a property, e.g. 'bearing 29'
def method_missing(method_sym, *args)
def add_property(method_sym, *args)
@kv[method_sym] = args[0]
end

Expand Down Expand Up @@ -60,7 +56,7 @@ def _add_layer(layer)

# Load file
def include_file(filename)
instance_eval(File.read(File.join(@base_dir, filename)))
@dsl.instance_eval(File.read(File.join(@base_dir, filename)))
end
end
end
32 changes: 32 additions & 0 deletions lib/glug/stylesheet_dsl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Glug
# Defines the methods available to the DSL
class StylesheetDSL
def initialize(impl)
@__impl = impl
end

def layer(id, opts = {}, &block)
@__impl.layer(id, opts, &block)
end

def source(source_name, opts = {})
@__impl.source(source_name, opts)
end

def include_file(filename)
@__impl.include_file(filename)
end

# Arbitrary properties can be defined, e.g. "foo :bar" results in a top-level "foo":"bar" in the style
def respond_to_missing?(*)
true
end

# Set a property, e.g. 'bearing 29'
def method_missing(method_sym, *args)
@__impl.add_property(method_sym, *args)
end
end
end