Class: Polyblock::PolyblocksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/polyblock/polyblocks_controller.rb

Instance Method Summary collapse

Instance Method Details

#convert_haml_to_html ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 16

def convert_haml_to_html
  haml = params[:haml]

  # Remove the pesky helpers
  haml = haml.split("= succeed \"")
  lines = [haml.shift]
  haml.each do |chunk|
    arg = chunk.split("\"",2)[0]
    block = chunk.split("\n")[1..-1].map{|line| line[2..-1]}.join("\n")
    lines << "#{block}\narg"
  end
  haml = lines.join("")

  # Run it through the engine
  render :text => Haml::Engine.new(haml).render
end

#convert_html_to_haml ⇒ Object



33
34
35
36
37
38
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 33

def convert_html_to_haml
  # html = if params.has_key? :cbid then ContentBlock.find(params[:cbid]).content else params[:html] end
  # engine = Html2haml::HTML.new html, :erb => false, :xhtml => false
  engine = Html2haml::HTML.new params[:html], :erb => false, :xhtml => false
  render :text => engine.render
end

#update ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 6

def update
  if params.has_key? :pbs and params[:pbs].any?
    params[:pbs].each do |id,content|
      pb = Block.find(id)
      pb.update_attributes!(:content => content) if pb.present?
    end
  end
  render :text => "OK!"
end