Class: Hamlit::Filters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hamlit/filters/base.rb

Direct Known Subclasses

Css, Escaped, Javascript, Plain, Preserve, Ruby, Tilt

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/hamlit/filters/base.rb', line 11

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/hamlit/filters/base.rb', line 4

def options
  @options
end

Class Method Details

.indent_source(source, indent_width: 0) ⇒ Object



6
7
8
9
# File 'lib/hamlit/filters/base.rb', line 6

def self.indent_source(source, indent_width: 0)
  lines = source.split("\n")
  self.new.compile_lines(lines, indent_width: indent_width)
end

Instance Method Details

#compile(lines) ⇒ Object

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/hamlit/filters/base.rb', line 15

def compile(lines)
  raise NotImplementedError
end

#compile_lines(lines, indent_width: 0) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hamlit/filters/base.rb', line 19

def compile_lines(lines, indent_width: 0)
  base  = (lines.first || '').index(/[^\s]/) || 0
  width = indent_width - base
  width = 0 if width < 0

  lines = strip_last(lines).map do |line|
    ' ' * width + line
  end

  text = lines.join("\n") + "\n"
  text
end