Class: Mack::Rendering::Type::Js

Inherits:
FileBase
  • Object
show all
Defined in:
lib/mack-javascript/rendering/type/js.rb

Overview

Used to render an XML template that’s relative to a controller.

Example:

class UsersController < Mack::Controller::Base
  # /users/:id
  def show
    @user = User.first(params(:id))
  end
  # /users
  def index
    @users = User.all
    render(:xml, :list)
  end
end

When some calls /users/1.xml the file: app/views/users/show.xml.builder will be rendered. When some calls /users.xml the file: app/views/users/list.xml.builder will be rendered.

Instance Method Summary collapse

Instance Method Details

#allow_layout?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mack-javascript/rendering/type/js.rb', line 30

def allow_layout?
  false
end

#renderObject

See Mack::Rendering::Type::FileBase render_file for more information.



23
24
25
26
27
28
# File 'lib/mack-javascript/rendering/type/js.rb', line 23

def render
  self._options[:format] = "js"
  self.controller.response["Content-Type"] = Mack::Utils::MimeTypes[self._options[:format]]
  x_file = File.join(self.controller_view_path, "#{self._render_value}.#{self._options[:format]}")
  render_file(x_file, :js)
end