Sha256: 752c94154b681f0517e20ea8bbb83575ece16a541ed1dccdaff575fb18f31f7a

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require_dependency "polyblock/application_controller"

module Polyblock
  class PolyblocksController < ApplicationController

    def update
      if params.has_key? :pbs and params[:pbs].any?
        params[:pbs].each do |i, attrs|
          pb_attrs = {}
          pb_attrs[:id] = attrs[:id] if attrs.has_key?(:id) and !attrs[:id].blank?
          pb_attrs[:name] = attrs[:name] if attrs.has_key?(:name) and !attrs[:name].blank?
          pb = Block.find_or_initialize_by pb_attrs
          pb.id = nil if Block.find(pb_attrs[:id]).present? and pb.new_record?
          pb.content = attrs[:content]
          pb.save!
        end
      end
      render :text => "OK!"
    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

1 entries across 1 versions & 1 rubygems

Version Path
polyblock-0.3.9 app/controllers/polyblock/polyblocks_controller.rb