Class: BmmlExporters::BmmlHtmlExporter

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

Defined Under Namespace

Classes: HtmlStyle

Instance Method Summary collapse

Constructor Details

#initialize(*opts) ⇒ BmmlHtmlExporter

Returns a new instance of BmmlHtmlExporter.



17
18
19
20
# File 'lib/bmmlhtmlexporter.rb', line 17

def initialize(*opts)
	super
	@output_content = ""
end

Instance Method Details

#exportObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/bmmlhtmlexporter.rb', line 151

def export
	@output_content = "<html><body>"
	i = 1
	@doc.root.each_element('//control') { |control|
		color = make_color
		type = control.attributes["controlTypeID"].gsub!(/com.balsamiq.mockups::/,'').to_s.downcase
		text = ""
		left = control.attributes["x"]
		top = control.attributes["y"]
		width = control.attributes["w"]
		if width.to_i == -1 and width.to_i < control.attributes["measuredW"].to_i
			width = control.attributes["measuredW"] 
		end
		height = control.attributes["h"] 
		if height.to_i == -1 and height.to_i < control.attributes["measuredH"].to_i
			height = control.attributes["measuredH"] 
		end
		zindex = control.attributes["zOrder"]

		style = HtmlStyle.new
		style["left"] = left
		style["top"] = top
		style["width"] = width
		style["height"] = height

		#	begin
		unless control[1].nil? or control[1][1].nil? or control[1][1].text.nil?
			text = control[1][1].text.url_decode
		end
		@output_content << "<div style=\"border: 0px black solid; background-color:"+"; position:absolute; z-index:"+zindex+';'+
			"left:"+left+"px;"+
			"top:"+top+"px;"+
			"width:"+width+"px;"+
			"height:"+height+"px;"+
			"\">"+render(type,format(text),style)+"</div><br />\n" unless width.nil? or height.nil?
		#	rescue Exception => e
		#		p "Control removed: "+control.to_s+" because "+e.message
		#	end
		i += 1
	}

	@output_content += "</body></html>"
end

#export!Object



199
200
201
202
# File 'lib/bmmlhtmlexporter.rb', line 199

def export!
	export
	save
end

#format(text) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/bmmlhtmlexporter.rb', line 51

def format(text)
	transformations = {
		"/_*_/" => "<b>\1</b>"
	}
	transformations.each do |what, how|
		#text.gsub!(what,how)
		text.gsub!(/_([^_]+)_/,'<b>\1</b>')
	end
	text
end

#make_colorObject



44
45
46
47
48
49
# File 'lib/bmmlhtmlexporter.rb', line 44

def make_color
	r = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
	#"#"+r[rand(1+15)] +  r[rand(1+15)] +  r[rand(1+15)] +  r[rand(1+15)] +  r[rand(1+15)] +  r[rand(1+15)] 
	r = ['blue','yellow','red','green','purple','pink','cyan']
	r[rand(r.size-1)+1]
end

#render(type, text, *args) ⇒ Object



40
41
42
# File 'lib/bmmlhtmlexporter.rb', line 40

def render(type,text,*args)
	send('render_'+type.to_s,text,*args)
end

#render_breadcrumbs(text, style) ⇒ Object



93
94
95
# File 'lib/bmmlhtmlexporter.rb', line 93

def render_breadcrumbs(text,style)
	text.split(',').join(' > ')
end

#render_button(text, style) ⇒ Object



62
63
64
65
66
67
# File 'lib/bmmlhtmlexporter.rb', line 62

def render_button(text,style)
	s = HtmlStyle.new
	s["width"] = style["width"]
	text = "no text found" if text.nil?
	'<button type="button" style="'+style.to_s+'">'+text+'</button>'
end

#render_buttonbar(text, style) ⇒ Object



97
98
99
# File 'lib/bmmlhtmlexporter.rb', line 97

def render_buttonbar(text,style)
	text
end

#render_canvas(text, style) ⇒ Object



116
117
118
# File 'lib/bmmlhtmlexporter.rb', line 116

def render_canvas(text,style)
	text
end

#render_checkbox(text, style) ⇒ Object



143
144
145
# File 'lib/bmmlhtmlexporter.rb', line 143

def render_checkbox(text,style)
	text+" <INPUT TYPE=CHECKBOX NAME=\""+text+"\">"
end

#render_combobox(text, style) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/bmmlhtmlexporter.rb', line 107

def render_combobox(text,style)
	render = "<select name=\"combobox\">"
	text.split('/').each do |t|
		render << "<option value=\""+t+"\">"+t+"</option>"
	end
	render << "</select></div>"
	render
end

#render_fieldset(text, style) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/bmmlhtmlexporter.rb', line 124

def render_fieldset(text,style)
	myStyle = HtmlStyle.new
	myStyle["width"] = style["width"].to_i - 20
	myStyle["height"] = style["height"].to_i - 20
	response = ""
	response << "</fieldset>" if $fieldset_was_already_opened
	response << "<fieldset style=\"height: " + myStyle["height"].to_s + "; width: " + myStyle["width"].to_s + "\"><legend>" + text + "</legend>"
	$fieldset_was_already_opened = true
	response
end

#render_formattingtoolbar(text, style) ⇒ Object



139
140
141
# File 'lib/bmmlhtmlexporter.rb', line 139

def render_formattingtoolbar(text,style)
	"<img src=\"images/formattingtoolbar.png\" />"
end

#render_hrule(text, style) ⇒ Object



120
121
122
# File 'lib/bmmlhtmlexporter.rb', line 120

def render_hrule(text,style)
	"<h />"
end

#render_label(text, style) ⇒ Object



89
90
91
# File 'lib/bmmlhtmlexporter.rb', line 89

def render_label(text,style)
	'<label for="'+text+'">'+text+'</label>'
end

#render_stickynote(text, style) ⇒ Object



147
148
149
# File 'lib/bmmlhtmlexporter.rb', line 147

def render_stickynote(text,style)
	"<div style=\"width: 100%; height: 100%;background-color: yellow;\"><b>Sticky note</b><br />"+text+"</div>"
end

#render_textarea(text, style) ⇒ Object



135
136
137
# File 'lib/bmmlhtmlexporter.rb', line 135

def render_textarea(text,style)
	"<textarea>"+text+"</textarea>"
end

#render_textinput(text, style) ⇒ Object



101
102
103
104
105
# File 'lib/bmmlhtmlexporter.rb', line 101

def render_textinput(text,style)
	myStyle = HtmlStyle.new
	myStyle["width"] = style["width"]
	'<input type="text" value="'+text+'" size='+(myStyle["width"].to_i/9).to_s+'>'
end

#render_titlewindow(text, style) ⇒ Object



69
70
71
# File 'lib/bmmlhtmlexporter.rb', line 69

def render_titlewindow(text,style)
	text
end

#render_tree(text, style) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bmmlhtmlexporter.rb', line 73

def render_tree(text,style)
	html = ""
	groups = text.split('F')
	groups.shift

	groups.each do |group|
		lines = group.split('%0A')
		html << "<ul>"+lines.shift
		lines.each do |line|
			html << "<li>"+line+"</li>"
		end
		html << "</ul>"
	end
	html
end

#saveObject



195
196
197
# File 'lib/bmmlhtmlexporter.rb', line 195

def save
	File.open(@output, 'w') {|f| f.write(@output_content) }
end

#set_options(*opts) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/bmmlhtmlexporter.rb', line 32

def set_options(*opts)
	options = *opts
	# :import (file,inline), :file(name.bmml), :export_type (html/flex), :export_folder('./output')

	@output = "output.html" #options[:export_folder]+'/index.html'
	@doc = Document.new(File.new(options[:file]))
end

#to_sObject



13
14
15
# File 'lib/bmmlhtmlexporter.rb', line 13

def to_s
	@output_content
end