Sha256: c8627f4e7f9ee72a1a8591f78630e5377415447b4625b41a1ea1af429ba2479e

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

class RIPController < Sinatra::Base
  set :method_override, true

  def initialize(project_root)
    @settings = ProjectSettings.new(project_root)
  end
  
  # Converts an entity to its XML representation
	def to_xml(entities)
	  content_type("text/xml")
		xml = Builder::XmlMarkup.new
		xml.instruct!
		if entities.class.to_s == "DataMapper::Collection" # Bad idea!, problem to be solved another day :)
		  xml.results do
  		  entities.each do |entity|
  		    convert_entity(entity, xml)
  		  end
		  end
	  else
	    convert_entity(entities, xml)
		end
	end
	
	def to_html(view, controller=self)
    content_type("text/html")
    Sinatra::Base.set(:views, File.join(@settings.view_directory, controller.class.to_s.downcase.gsub("controller", "")))
    @yield = erb(view)
    ERB.new(File.open(File.join(@settings.view_directory, "layouts", "application.html.erb")).read).result(binding)
	end
	
	private
	
	def convert_entity(entity, xml)
		xml.tag!(entity.class.to_s.downcase) do |b|
  		entity.instance_variables.each do |v|
  		  unless v.match(/@_*/).to_s == "@_"
  			  b.tag!(v.gsub("@", ""), entity.instance_variable_get(v))
			  end
  		end
  	end	 
	end
		
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest_in_peace-0.1.1 lib/rest_in_peace/rip_controller.rb
rest_in_peace-0.1.0 lib/rest_in_peace/rip_controller.rb