Module: Sinatra::EngineTracking

Included in:
Capture
Defined in:
lib/sinatra/engine_tracking.rb

Overview

Adds methods like ‘haml?` that allow helper methods to check whether they are called from within a template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_engineObject (readonly)

Returns the value of attribute current_engine.



9
10
11
# File 'lib/sinatra/engine_tracking.rb', line 9

def current_engine
  @current_engine
end

Instance Method Details

#builder?Boolean

Returns true if current engine is ‘:builder`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:builder`.



41
42
43
# File 'lib/sinatra/engine_tracking.rb', line 41

def builder?
  @current_engine == :builder
end

#erb?Boolean

Returns true if current engine is ‘:erb`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:erb`.



12
13
14
# File 'lib/sinatra/engine_tracking.rb', line 12

def erb?
  @current_engine == :erb
end

#erubi?Boolean

Returns true if the current engine is ‘:erubi`, or `Tilt` is set to Tilt::ErubiTemplate.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:erubi`.



20
21
22
23
# File 'lib/sinatra/engine_tracking.rb', line 20

def erubi?
  @current_engine == :erubi or
    (erb? && Tilt[:erb] == Tilt::ErubiTemplate)
end

#haml?Boolean

Returns true if current engine is ‘:haml`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:haml`.



26
27
28
# File 'lib/sinatra/engine_tracking.rb', line 26

def haml?
  @current_engine == :haml
end

#initializeObject



80
81
82
83
# File 'lib/sinatra/engine_tracking.rb', line 80

def initialize(*)
  @current_engine = :ruby
  super
end

#liquid?Boolean

Returns true if current engine is ‘:liquid`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:liquid`.



46
47
48
# File 'lib/sinatra/engine_tracking.rb', line 46

def liquid?
  @current_engine == :liquid
end

#markaby?Boolean

Returns true if current engine is ‘:markaby`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:markaby`.



61
62
63
# File 'lib/sinatra/engine_tracking.rb', line 61

def markaby?
  @current_engine == :markaby
end

#markdown?Boolean

Returns true if current engine is ‘:markdown`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:markdown`.



51
52
53
# File 'lib/sinatra/engine_tracking.rb', line 51

def markdown?
  @current_engine == :markdown
end

#nokogiri?Boolean

Returns true if current engine is ‘:nokogiri`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:nokogiri`.



66
67
68
# File 'lib/sinatra/engine_tracking.rb', line 66

def nokogiri?
  @current_engine == :nokogiri
end

#rdoc?Boolean

Returns true if current engine is ‘:rdoc`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:rdoc`.



56
57
58
# File 'lib/sinatra/engine_tracking.rb', line 56

def rdoc?
  @current_engine == :rdoc
end

#ruby?Boolean

Returns true if current engine is ‘:ruby`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:ruby`.



76
77
78
# File 'lib/sinatra/engine_tracking.rb', line 76

def ruby?
  @current_engine == :ruby
end

#sass?Boolean

Returns true if current engine is ‘:sass`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:sass`.



31
32
33
# File 'lib/sinatra/engine_tracking.rb', line 31

def sass?
  @current_engine == :sass
end

#scss?Boolean

Returns true if current engine is ‘:scss`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:scss`.



36
37
38
# File 'lib/sinatra/engine_tracking.rb', line 36

def scss?
  @current_engine == :scss
end

#slim?Boolean

Returns true if current engine is ‘:slim`.

Returns:

  • (Boolean)

    Returns true if current engine is ‘:slim`.



71
72
73
# File 'lib/sinatra/engine_tracking.rb', line 71

def slim?
  @current_engine == :slim
end

#with_engine(engine) ⇒ Object

Parameters:

  • engine (Symbol, String)

    Name of Engine to shift to.



86
87
88
89
90
91
92
# File 'lib/sinatra/engine_tracking.rb', line 86

def with_engine(engine)
  engine_was = @current_engine
  @current_engine = engine.to_sym
  yield
ensure
  @current_engine = engine_was
end