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
-
#current_engine ⇒ Object
readonly
Returns the value of attribute current_engine.
Instance Method Summary collapse
-
#builder? ⇒ Boolean
Returns true if current engine is ‘:builder`.
-
#erb? ⇒ Boolean
Returns true if current engine is ‘:erb`.
-
#erubi? ⇒ Boolean
Returns true if the current engine is ‘:erubi`, or `Tilt` is set to Tilt::ErubiTemplate.
-
#haml? ⇒ Boolean
Returns true if current engine is ‘:haml`.
- #initialize ⇒ Object
-
#liquid? ⇒ Boolean
Returns true if current engine is ‘:liquid`.
-
#markaby? ⇒ Boolean
Returns true if current engine is ‘:markaby`.
-
#markdown? ⇒ Boolean
Returns true if current engine is ‘:markdown`.
-
#nokogiri? ⇒ Boolean
Returns true if current engine is ‘:nokogiri`.
-
#rdoc? ⇒ Boolean
Returns true if current engine is ‘:rdoc`.
-
#ruby? ⇒ Boolean
Returns true if current engine is ‘:ruby`.
-
#sass? ⇒ Boolean
Returns true if current engine is ‘:sass`.
-
#scss? ⇒ Boolean
Returns true if current engine is ‘:scss`.
-
#slim? ⇒ Boolean
Returns true if current engine is ‘:slim`.
- #with_engine(engine) ⇒ Object
Instance Attribute Details
#current_engine ⇒ Object (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`.
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`.
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.
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`.
26 27 28 |
# File 'lib/sinatra/engine_tracking.rb', line 26 def haml? @current_engine == :haml end |
#initialize ⇒ Object
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`.
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`.
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`.
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`.
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`.
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`.
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`.
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`.
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`.
71 72 73 |
# File 'lib/sinatra/engine_tracking.rb', line 71 def slim? @current_engine == :slim end |
#with_engine(engine) ⇒ Object
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 |