Module: Stencils::Stencil

Included in:
ActionController::Base
Defined in:
lib/stencils/stencil.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/stencils/stencil.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#custom_stencil_template_exists?(action = ) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/stencils/stencil.rb', line 52

def custom_stencil_template_exists?(action=params[:action])
  custom_template_path = File.join(RAILS_ROOT, 'app', 'views', "#{stencil.collection_name}", action.to_s)
  File.exist?("#{custom_template_path}.html.erb") || File.exist?("#{custom_template_path}.erb")
end

#render_stencil(action = nil, options = {}) ⇒ Object



42
43
44
45
46
# File 'lib/stencils/stencil.rb', line 42

def render_stencil(action=nil, options={})
  action, options = nil, action if action.is_a? Hash
  action ||= params[:action]
  render(:template => stencil_template(action)) unless custom_stencil_template_exists?(action)
end

#setup_stencil(model_or_class_or_symbol) ⇒ Object



38
39
40
# File 'lib/stencils/stencil.rb', line 38

def setup_stencil(model_or_class_or_symbol)
  @stencil ||= StencilContext.new(self.response.template, model_or_class_or_symbol, self.class.stencil_options)
end

#stencil_filterObject



34
35
36
# File 'lib/stencils/stencil.rb', line 34

def stencil_filter
  setup_stencil(self)
end

#stencil_template(action) ⇒ Object



48
49
50
# File 'lib/stencils/stencil.rb', line 48

def stencil_template(action)
  "stencils/#{stencil.stencil_name}/#{action}"
end