Module: ErbToSlim::Pattern

Included in:
Engine
Defined in:
lib/erb_to_slim/pattern.rb

Instance Method Summary collapse

Instance Method Details

#close_tagObject



31
32
33
# File 'lib/erb_to_slim/pattern.rb', line 31

def close_tag
  /\s*(<% *end *-?%>|(@ )?<\/\w+>)$/
end

#erb_eval_tagObject



39
40
41
# File 'lib/erb_to_slim/pattern.rb', line 39

def erb_eval_tag
  /^(#{indentation})(#{html_tags_list})? *<%=\s*(#{multiline_string_which_not_match('<%=')})\s*-?%>$/
end

#erb_exec_tagObject



27
28
29
# File 'lib/erb_to_slim/pattern.rb', line 27

def erb_exec_tag
  /<%(?!=)-?\s*((?m:.*?))\s*-?%>/
end

#html_tagObject



35
36
37
# File 'lib/erb_to_slim/pattern.rb', line 35

def html_tag
  /^(#{indentation})<(\w+)(.*?) *(?<!%)\/?> *(.*)?/
end

#html_tags_arrayObject



5
6
7
8
# File 'lib/erb_to_slim/pattern.rb', line 5

def html_tags_array
  @html_tags_array ||= File.readlines(File.expand_path('../html_tag_list.txt', __FILE__))
    .reject {|line| line =~ /^#|^$/ }.map(&:chomp)
end

#html_tags_listObject



10
11
12
# File 'lib/erb_to_slim/pattern.rb', line 10

def html_tags_list
  @html_tags_list ||= html_tags_array.join('|')
end

#indentationObject



14
15
16
# File 'lib/erb_to_slim/pattern.rb', line 14

def indentation
  /[\s\t]*+/
end

#js_tagObject



23
24
25
# File 'lib/erb_to_slim/pattern.rb', line 23

def js_tag
  /<script *(type="text\/javascript")? *>(#{multiline_string_which_not_match('<script')})<\/script>/
end

#multiline_string_which_not_match(str) ⇒ Object



18
19
20
21
# File 'lib/erb_to_slim/pattern.rb', line 18

def multiline_string_which_not_match(str)
  str_escaped = str.gsub(/[!<>=?]/, '\\\\\&')
  /(?:.(?!#{str_escaped}))*?/m
end

#string_literalObject



43
44
45
# File 'lib/erb_to_slim/pattern.rb', line 43

def string_literal
  /^(#{indentation})((?:#{html_tags_list}|\||-|=|\#|@))?\b *(.*)$/
end

#tag_with_classObject



51
52
53
# File 'lib/erb_to_slim/pattern.rb', line 51

def tag_with_class
  /([\w#]+)(.*?) *class *= *(["'])(.*?)\3(.*?) *$/
end

#tag_with_idObject



47
48
49
# File 'lib/erb_to_slim/pattern.rb', line 47

def tag_with_id
  /(\w+)(.*?) *id *= *(["'])(.*?)\3(.*?) *$/
end