Module: Synvert::Core::Engine

Defined in:
lib/synvert/core/engine.rb,
lib/synvert/core/engine/erb.rb,
lib/synvert/core/engine/haml.rb,
lib/synvert/core/engine/slim.rb,
lib/synvert/core/engine/elegant.rb

Overview

Engine defines how to encode / decode other files (like erb).

Defined Under Namespace

Modules: Elegant Classes: Erb, Haml, Slim

Class Method Summary collapse

Class Method Details

.encode(extension, source) ⇒ String

Encode source code by registered engine.

Parameters:

  • extension (String)
  • source (String)

Returns:

  • (String)

    encoded source



25
26
27
28
# File 'lib/synvert/core/engine.rb', line 25

def self.encode(extension, source)
  engine = @engines[extension]
  engine ? engine.encode(source) : source
end

.generate_transform_proc(extension, encoded_source) ⇒ Proc

Generate a transform_proc by registered engine, which is used to adjust start and end position of actions.

Parameters:

  • extension (String)
  • encoded_source (String)

Returns:

  • (Proc)

    transform_proc



35
36
37
38
# File 'lib/synvert/core/engine.rb', line 35

def self.generate_transform_proc(extension, encoded_source)
  engine = @engines[extension]
  engine ? engine.generate_transform_proc(encoded_source) : proc {}
end

.register(extension, engine) ⇒ Object

Register an engine

Parameters:

  • extension (String)
  • engine (Class)


16
17
18
19
# File 'lib/synvert/core/engine.rb', line 16

def self.register(extension, engine)
  @engines ||= {}
  @engines[extension] = engine
end