Module: Kiosk::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/kiosk/controller.rb
Overview
Adds the ability to declare content rewrites in a controller.
Instance Method Summary collapse
-
#rewrite_cdn_paths_for(resource_model) ⇒ Object
Declares a rewrite of content nodes that sets the host portion of each node’s URI attribute (href or src) to target the configured CDN host.
-
#rewrite_content_for(resource_model, &blk) ⇒ Object
Declares a rewrite of content nodes.
-
#rewrite_paths_for(resource_model, &blk) ⇒ Object
Declares a rewrite of content nodes that sets a new URL any href or src attributes (the first one found, it that order).
Instance Method Details
#rewrite_cdn_paths_for(resource_model) ⇒ Object
Declares a rewrite of content nodes that sets the host portion of each node’s URI attribute (href or src) to target the configured CDN host.
13 14 15 |
# File 'lib/kiosk/controller.rb', line 13 def rewrite_cdn_paths_for(resource_model) Kiosk.rewriter.add_rewrite(Rewrite.new(:cdn, resource_model)) end |
#rewrite_content_for(resource_model, &blk) ⇒ Object
Declares a rewrite of content nodes.
Example:
class PostsController
include Kiosk::Controller
before_filter do
rewrite_content_for(Attachment) do |,node|
case node.name
when 'a'
node['title'] = 'Some photo'
when 'img'
node['src'] = (.filename)
end
end
end
end
36 37 38 |
# File 'lib/kiosk/controller.rb', line 36 def rewrite_content_for(resource_model, &blk) Kiosk.rewriter.add_rewrite(Rewrite.new(:node, resource_model, &blk)) end |
#rewrite_paths_for(resource_model, &blk) ⇒ Object
Declares a rewrite of content nodes that sets a new URL any href or src attributes (the first one found, it that order). The given block is passed the instantiated resource and node as its arguments and should return the new value for the node attribute.
Example:
class PostsController
include Kiosk::Controller
before_filter do
rewrite_paths_for(Post) { |post| post_path(post.slug) }
end
end
55 56 57 |
# File 'lib/kiosk/controller.rb', line 55 def rewrite_paths_for(resource_model, &blk) Kiosk.rewriter.add_rewrite(Rewrite.new(:path, resource_model, &blk)) end |