Class: ExtractI18n::Adapters::SlimRewriterParser::CustomFilter

Inherits:
Slim::Filter
  • Object
show all
Defined in:
lib/extract_i18n/adapters/slim_adapter_wip.rb

Instance Method Summary collapse

Instance Method Details

#block(content) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 45

def block(content)
  @indent += 1
  result = compile(content).to_s # todo remove to_s
  if result.is_a?(String)
    extract_from_string(result)
  else
    result
  end
ensure
  @indent -= 1
end

#call(exp) ⇒ Object



16
17
18
19
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 16

def call(exp)
  @indent = 0
  super.to_s
end

#extract_from_string(string) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 57

def extract_from_string(string)
  i18n_key = ExtractI18n.key(string)
  change = ExtractI18n::SourceChange.new(
    i18n_key: "#{@options[:file_key]}.#{i18n_key}",
    i18n_string: string,
    interpolate_arguments: {},
    source_line: string,
    remove: string
  )
  puts change.format
  if @options[:on_ask].call(change)
    change.i18n_t
  else
    string
  end
end

#indentObject



102
103
104
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 102

def indent
  '  ' * @indent
end

#on_html_attr(name, content) ⇒ Object



98
99
100
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 98

def on_html_attr(name, content)
  "#{name}=#{compile content}"
end

#on_html_attrs(*attrs) ⇒ Object



74
75
76
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 74

def on_html_attrs(*attrs)
  attrs.empty? ? '' : "(#{super[2..-1].join(' ')})"
end

#on_html_comment(exp) ⇒ Object



90
91
92
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 90

def on_html_comment(exp)
  "#{indent}/ #{block exp}"
end

#on_html_doctype(name) ⇒ Object



33
34
35
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 33

def on_html_doctype(name)
  "#{indent}doctype #{name}"
end

#on_html_tag(name, attrs, content = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 37

def on_html_tag(name, attrs, content = nil)
  ret = "#{indent}#{name}#{compile attrs}"
  if content
    ret << ' ' << block(content)
  end
  ret
end

#on_multi(*exps) ⇒ Object



21
22
23
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 21

def on_multi(*exps)
  super[1..-1].join
end

#on_newlineObject



25
26
27
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 25

def on_newline
  "\n"
end

#on_slim_control(line, block) ⇒ Object



94
95
96
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 94

def on_slim_control(line, block)
  "#{indent}- #{line}#{block block}"
end

#on_slim_embedded(type, text) ⇒ Object



86
87
88
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 86

def on_slim_embedded(type, text)
  "#{indent}#{block text}"
end

#on_slim_interpolate(text) ⇒ Object



78
79
80
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 78

def on_slim_interpolate(text)
  compile(text)
end

#on_slim_text(type, text) ⇒ Object



82
83
84
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 82

def on_slim_text(type, text)
  block(text)
end

#on_static(*args) ⇒ Object



29
30
31
# File 'lib/extract_i18n/adapters/slim_adapter_wip.rb', line 29

def on_static(*args)
  args[0].include?('"') ? "'#{args.join(' ')}'" : %["#{args.join(' ')}"]
end