Sha256: c83e59a688dc5546f2da4f0806e8504d285b6ebffdffc94bd00943596ebd4f81

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'webrick'

#
# Simple ajax interaction with Concrete editor
#
# Adapt the path to the browser (Firefox or Chrome) below.
# Startup the browser before you run this script, otherwise it might hang.
#
Browser = "firefox"
Port = 1234

class ConcreteServer
	
	def initialize(file)
		@file = file
		@server = WEBrick::HTTPServer.new(:Port => Port)
		@server.mount_proc("/") do |req, res|
			handleRequest(req, res)
		end
	end
	
	def start
		@server.start do |sock|
			@server.run(sock)
		end
	end
	
	private

	def handleRequest(req, res)
		if req.path == "/"
			res.body = File.read("metamodel_editor.html").sub("<!-- json model here -->", File.read(@file))
		elsif req.path == "/save"
			File.open(@file, "w") {|f| f.write(req.body)}
		elsif req.path == "/exit"
			@server.shutdown
    elsif req.path == "/favicon.ico"
      # ignore
		else
			res.body = File.read("../.."+req.path)
		end
	end	
		
end

if (ARGV.size == 0)
	puts "Usage: edit.rb <json file>"
	exit
end

# if the browser is not yet running the following line might block
system "#{Browser} http://localhost:#{Port}/"
ConcreteServer.new(ARGV[0]).start

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
concrete-0.2.1 example/metamodel_editor/edit.rb
concrete-0.2.0 example/metamodel_editor/edit.rb