Sha256: 81a58c7c9283ec77e4dc81960f06851d452f7d9c67e6307204b238fdd860be4b

Contents?: true

Size: 1.59 KB

Versions: 15

Compression:

Stored size: 1.59 KB

Contents

require_dependency "polyblock/application_controller"

module Polyblock
  class PolyblocksController < ApplicationController

    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

    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

    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

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
polyblock-0.9.5 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.9.4 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.9.3 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.9.2 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.8 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.7 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.6 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.5 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.4 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.3 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.2 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.1 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.8.0 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.7.2 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.7.1 app/controllers/polyblock/polyblocks_controller.rb