123456789_123456789_123456789_123456789_123456789_

Module: Sinatra::EngineTracking

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: sinatra-contrib/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

Instance Method Summary

Instance Attribute Details

#builder?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :builder.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 41

def builder?
  @current_engine == :builder
end

#current_engine (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 9

attr_reader :current_engine

#erb?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :erb.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 12

def erb?
  @current_engine == :erb
end

#erubi?Boolean (readonly)

Returns true if the current engine is :erubi, or Tilt[:erb] is set to Tilt::ErubiTemplate.

Returns:

  • (Boolean)

    Returns true if current engine is :erubi.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 20

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

#haml?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :haml.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 26

def haml?
  @current_engine == :haml
end

#liquid?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :liquid.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 46

def liquid?
  @current_engine == :liquid
end

#markaby?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :markaby.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 61

def markaby?
  @current_engine == :markaby
end

#markdown?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :markdown.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 51

def markdown?
  @current_engine == :markdown
end

#nokogiri?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :nokogiri.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 66

def nokogiri?
  @current_engine == :nokogiri
end

#rdoc?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :rdoc.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 56

def rdoc?
  @current_engine == :rdoc
end

#ruby?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :ruby.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 76

def ruby?
  @current_engine == :ruby
end

#sass?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :sass.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 31

def sass?
  @current_engine == :sass
end

#scss?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :scss.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 36

def scss?
  @current_engine == :scss
end

#slim?Boolean (readonly)

Returns:

  • (Boolean)

    Returns true if current engine is :slim.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 71

def slim?
  @current_engine == :slim
end

Instance Method Details

#initialize

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 80

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

#render(engine) (private)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/engine_tracking.rb', line 96

def render(engine, *)
  with_engine(engine) { super }
end

#with_engine(engine)

Parameters:

  • engine (Symbol, String)

    Name of Engine to shift to.

[ GitHub ]

  
# File 'sinatra-contrib/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