Sha256: c6995c068d5681a899e0f8c6efcf786fae985f1834f7f795e734dbca952f27c2

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 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.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

7 entries across 7 versions & 1 rubygems

Version Path
polyblock-0.3.7 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.6 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.5 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.4 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.3 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.2 app/controllers/polyblock/polyblocks_controller.rb
polyblock-0.3.1 app/controllers/polyblock/polyblocks_controller.rb