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_htmlObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 28

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_hamlObject



45
46
47
48
49
50
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 45

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

#updateObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/polyblock/polyblocks_controller.rb', line 6

def update
  if params.key?(:pbs) && params[:pbs].any?
    params[:pbs].each do |i, attrs|
      pb_find = Block.where(:id => attrs[:id])
      attrs.delete(:id)
      if pb_find.any? && pb_find.first.name == attrs[:name]
        pb_find.first.update_attributes!(attrs)
      else
        Block.create! attrs
      end
    end
    render :text => "OK!"
  elsif params.key?(:polyblocks)
    params[:polyblocks].each do |name, pb_attrs|
      pb = Block.fetch_or_create name
      pb.update_attributes! pb_attrs
    end
    flash[:success] = 'Your polyblocks have been updated!'
    redirect_to :back
  end
end