Class: Glader

Inherits:
Object
  • Object
show all
Defined in:
lib/glader.rb

Overview

This class is a quick way of creating a runnable Ruby program from a single Glade form.

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Constructor Details

#initialize(glade_filename) ⇒ Glader

Returns a new instance of Glader.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/glader.rb', line 9

def initialize(glade_filename)
	raise ArgumentError.new("File missing: #{glade_filename}") if	!File.exist?(glade_filename)
	raise ArgumentError.new("Not a .glade file: #{glade_filename}") if glade_filename !~ /.*\.glade/

	@glade_filename = glade_filename
	@base_filename = File.basename(@glade_filename, ".glade")
	@class_filename = @base_filename + "_glade.rb"
end

Instance Method Details

#make_classObject

Runs the ruby-glade-create-template script to create a file with a class that corresponds to the form. This can be called repeatedly to keep creating the class every time the .glade file changes.



22
23
24
25
# File 'lib/glader.rb', line 22

def make_class
	`/usr/bin/ruby-glade-create-template #{@glade_filename} > #{@class_filename}`
	@class_filename
end

#make_mainObject

Creates a main program that uses the glade class created with make_class and opens the window with the form. It will do nothing if the main program file already exists, since the user is likely to add code to this file.



32
33
34
35
36
37
38
39
40
41
# File 'lib/glader.rb', line 32

def make_main
	main_filename = @base_filename + '.rb'

	if(File.exist?(main_filename))
		raise ArgumentError.new("#{main_filename} already exists, skipping")
	else
		File.open(main_filename, "w") {|f| f.write generate_main}
	end
	main_filename
end