Class: Less::Node::Mixin::Def

Inherits:
Element show all
Defined in:
lib/less/engine/nodes/element.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#file, #imported, #name, #rules, #selector, #set

Attributes included from Entity

#parent

Instance Method Summary collapse

Methods inherited from Element

#<<, #==, #[], #class?, #descend, #each, #elements, #empty?, #eql?, #equiv?, #first, #group, #id?, #identifiers, #last, #leaf?, #mixins, #nearest, #parameters, #properties, #root?, #tag?, #universal?

Methods included from Entity

#path, #root

Constructor Details

#initialize(name, params = []) ⇒ Def

Returns a new instance of Def.



237
238
239
240
241
242
# File 'lib/less/engine/nodes/element.rb', line 237

def initialize name, params = []
  super name
  @params = params.each do |param|
    param.parent = self
  end
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



235
236
237
# File 'lib/less/engine/nodes/element.rb', line 235

def params
  @params
end

Instance Method Details

#call(args = []) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/less/engine/nodes/element.rb', line 244

def call args = []
  if e = @rules.find {|r| r.is_a? Element }
    raise CompileError, "#{e} in #{self.inspect}: can't nest selectors inside a dynamic mixin."
  end

  env = Element.new

  @params.zip(args).each do |param, val|
    env << (val ? Variable.new(param.to_s, Expression.new([val])) : param)
  end

  #b ? Node::Variable.new(a.to_s, Expression.new([b])) : a

#          puts "#{self.inspect}"
#          puts "env: #{env.variables}      root?: #{env.root?}"
#          puts "\nTOCSS"
  to_css([], env)
end

#inspectObject



271
272
273
# File 'lib/less/engine/nodes/element.rb', line 271

def inspect
  ".#{name}()"
end

#to_css(path, env) ⇒ Object



275
276
277
# File 'lib/less/engine/nodes/element.rb', line 275

def to_css path, env
  super(path, env)
end

#to_sObject



267
268
269
# File 'lib/less/engine/nodes/element.rb', line 267

def to_s
  '.' + name
end

#variablesObject



263
264
265
# File 'lib/less/engine/nodes/element.rb', line 263

def variables
  params + super
end