Module: Fdlint::Rule::DSL

Extended by:
DSL
Included in:
DSL
Defined in:
lib/fdlint/rule/dsl.rb

Instance Method Summary collapse

Instance Method Details

#after(element, &block) ⇒ Object



76
77
78
79
# File 'lib/fdlint/rule/dsl.rb', line 76

def after( element, &block )
  @scope = element.intern
  rule &block
end

#before(element, &block) ⇒ Object



71
72
73
74
# File 'lib/fdlint/rule/dsl.rb', line 71

def before( element, &block )
  @scope = :"before_parse_#{element}"
  rule &block
end

#check(node, &block) ⇒ Object Also known as: review



47
48
49
50
51
52
53
54
# File 'lib/fdlint/rule/dsl.rb', line 47

def check( node, &block )
  @scope = node.intern
  if block && block.arity > 0
    rule &block
  else
    yield if block_given?
  end
end

#css_rules(&block) ⇒ Object



22
23
24
# File 'lib/fdlint/rule/dsl.rb', line 22

def css_rules( &block )
  rules_for( :css, &block )
end

#desc(description = nil) ⇒ Object



39
40
41
# File 'lib/fdlint/rule/dsl.rb', line 39

def desc( description=nil )
  @desc = description
end

#group(grp, &block) ⇒ Object



34
35
36
37
# File 'lib/fdlint/rule/dsl.rb', line 34

def group( grp, &block )
  @group = grp
  yield if block_given?
end

#helpers(target, &block) ⇒ Object

Public: Extend target class

target - An String or Class object



10
11
12
13
14
15
# File 'lib/fdlint/rule/dsl.rb', line 10

def helpers( target, &block )
  if target.is_a? String
    target = Object.const_get target.capitalize
  end
  target.class_eval &block
end

#html_rules(&block) ⇒ Object



26
27
28
# File 'lib/fdlint/rule/dsl.rb', line 26

def html_rules( &block )
  rules_for( :html, &block )
end

#js_rules(&block) ⇒ Object



30
31
32
# File 'lib/fdlint/rule/dsl.rb', line 30

def js_rules( &block )
  rules_for( :js, &block )
end

#rule(&block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fdlint/rule/dsl.rb', line 58

def rule( &block )
  @syntaxes.each do |syntax|
    ::Fdlint::Rule.add syntax, @scope, {
      :block => block,
      :desc  => @desc,
      :uri   => @uri
    }
  end

  @desc = nil
  @uri  = nil
end

#rules_for(*syntaxes, &block) ⇒ Object



17
18
19
20
# File 'lib/fdlint/rule/dsl.rb', line 17

def rules_for( *syntaxes, &block )
  @syntaxes = syntaxes.map(&:intern)
  yield if block_given?
end

#uri(u) ⇒ Object



43
44
45
# File 'lib/fdlint/rule/dsl.rb', line 43

def uri( u )
  @uri = u
end