bmmlexporter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.rdoc +57 -0
- data/lib/bmmlexporter.rb +56 -0
- data/lib/bmmlhtmlexporter.rb +204 -0
- metadata +56 -0
data/History.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= bmmlexporter
|
2
|
+
|
3
|
+
* http://cesario.github.com/bmmlexporter
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
bmmlexporter provides an easy way to convert a bmml file to HTML or SWF.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Export to HTML with plenty of div's
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
$:.push('bmmlexporter')
|
16
|
+
|
17
|
+
require 'bmmlhtmlexporter'
|
18
|
+
include BmmlExporters
|
19
|
+
|
20
|
+
exporter = BmmlExporters::BmmlExporter.new :import => 'file', :file => 'mu.bmml', :export_type => 'html', :export_folder => 'output/', :exporter => BmmlExporters::BmmlHtmlExport.new
|
21
|
+
exporter.export!
|
22
|
+
p "Export done"
|
23
|
+
p exporter.to_s
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
* cgi
|
28
|
+
* rexml/document
|
29
|
+
|
30
|
+
== INSTALL:
|
31
|
+
|
32
|
+
* FIX (sudo gem install, anything else)
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Copyright (c) 2009 Franck Verrot
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
+
a copy of this software and associated documentation files (the
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
46
|
+
the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be
|
49
|
+
included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/bmmlexporter.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
# $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'cgi'
|
5
|
+
require File.dirname(__FILE__) + '/bmmlhtmlexporter'
|
6
|
+
include REXML
|
7
|
+
|
8
|
+
module BmmlExporters
|
9
|
+
VERSION = '0.0.1'
|
10
|
+
|
11
|
+
class BmmlExporter
|
12
|
+
attr_accessor :opts
|
13
|
+
def initialize(*opts)
|
14
|
+
set_options(*opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
check_response_and_call(@exporter, :to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_options(*opts)
|
22
|
+
options = *opts
|
23
|
+
|
24
|
+
raise "Require :import parameter" if options[:import].to_s.nil?
|
25
|
+
raise "Require :export_type parameter" if options[:export_type].to_s.nil?
|
26
|
+
|
27
|
+
if options[:import].eql? "file"
|
28
|
+
raise "Require :file if :import => 'file'" if options[:file].nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
raise "Require a valid :export_type: html / flex, mentioned " + options[:export_type] unless options[:export_type].eql? 'html' or options[:export_type].eql? 'flex'
|
32
|
+
|
33
|
+
# Reminder: :import (file,inline), :file(name.bmml), :export_type (html/flex), :export_folder('./output')
|
34
|
+
@exporter = options[:exporter]
|
35
|
+
check_response_and_call(@exporter, :set_options, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def export
|
39
|
+
check_response_and_call(@exporter, :export)
|
40
|
+
end
|
41
|
+
|
42
|
+
def save
|
43
|
+
check_response_and_call(@exporter, :save)
|
44
|
+
end
|
45
|
+
|
46
|
+
def export!
|
47
|
+
export
|
48
|
+
save
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_response_and_call(obj, method_symbol, *args)
|
52
|
+
raise 'The exporter '+obj.class.to_s+' does not respond to the method '+method_symbol.to_s unless obj and obj.respond_to?(method_symbol)
|
53
|
+
obj.send(method_symbol, *args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
#require 'bmmlexporter'
|
2
|
+
#require File.dirname(__FILE__) + '/../lib/bmmlexporter'
|
3
|
+
|
4
|
+
class String
|
5
|
+
def url_decode
|
6
|
+
CGI::unescape(self)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module BmmlExporters
|
11
|
+
|
12
|
+
class BmmlHtmlExporter
|
13
|
+
def to_s
|
14
|
+
@output_content
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(*opts)
|
18
|
+
super
|
19
|
+
@output_content = ""
|
20
|
+
end
|
21
|
+
|
22
|
+
class HtmlStyle < Hash
|
23
|
+
def to_s
|
24
|
+
s = ""
|
25
|
+
each { |key,value|
|
26
|
+
s << key+": "+value+";"
|
27
|
+
}
|
28
|
+
s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_options(*opts)
|
33
|
+
options = *opts
|
34
|
+
# :import (file,inline), :file(name.bmml), :export_type (html/flex), :export_folder('./output')
|
35
|
+
|
36
|
+
@output = "output.html" #options[:export_folder]+'/index.html'
|
37
|
+
@doc = Document.new(File.new(options[:file]))
|
38
|
+
end
|
39
|
+
|
40
|
+
def render(type,text,*args)
|
41
|
+
send('render_'+type.to_s,text,*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def make_color
|
45
|
+
r = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
|
46
|
+
#"#"+r[rand(1+15)] + r[rand(1+15)] + r[rand(1+15)] + r[rand(1+15)] + r[rand(1+15)] + r[rand(1+15)]
|
47
|
+
r = ['blue','yellow','red','green','purple','pink','cyan']
|
48
|
+
r[rand(r.size-1)+1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def format(text)
|
52
|
+
transformations = {
|
53
|
+
"/_*_/" => "<b>\1</b>"
|
54
|
+
}
|
55
|
+
transformations.each do |what, how|
|
56
|
+
#text.gsub!(what,how)
|
57
|
+
text.gsub!(/_([^_]+)_/,'<b>\1</b>')
|
58
|
+
end
|
59
|
+
text
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_button(text,style)
|
63
|
+
s = HtmlStyle.new
|
64
|
+
s["width"] = style["width"]
|
65
|
+
text = "no text found" if text.nil?
|
66
|
+
'<button type="button" style="'+style.to_s+'">'+text+'</button>'
|
67
|
+
end
|
68
|
+
|
69
|
+
def render_titlewindow(text,style)
|
70
|
+
text
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_tree(text,style)
|
74
|
+
html = ""
|
75
|
+
groups = text.split('F')
|
76
|
+
groups.shift
|
77
|
+
|
78
|
+
groups.each do |group|
|
79
|
+
lines = group.split('%0A')
|
80
|
+
html << "<ul>"+lines.shift
|
81
|
+
lines.each do |line|
|
82
|
+
html << "<li>"+line+"</li>"
|
83
|
+
end
|
84
|
+
html << "</ul>"
|
85
|
+
end
|
86
|
+
html
|
87
|
+
end
|
88
|
+
|
89
|
+
def render_label(text,style)
|
90
|
+
'<label for="'+text+'">'+text+'</label>'
|
91
|
+
end
|
92
|
+
|
93
|
+
def render_breadcrumbs(text,style)
|
94
|
+
text.split(',').join(' > ')
|
95
|
+
end
|
96
|
+
|
97
|
+
def render_buttonbar(text,style)
|
98
|
+
text
|
99
|
+
end
|
100
|
+
|
101
|
+
def render_textinput(text,style)
|
102
|
+
myStyle = HtmlStyle.new
|
103
|
+
myStyle["width"] = style["width"]
|
104
|
+
'<input type="text" value="'+text+'" size='+(myStyle["width"].to_i/9).to_s+'>'
|
105
|
+
end
|
106
|
+
|
107
|
+
def render_combobox(text,style)
|
108
|
+
render = "<select name=\"combobox\">"
|
109
|
+
text.split('/').each do |t|
|
110
|
+
render << "<option value=\""+t+"\">"+t+"</option>"
|
111
|
+
end
|
112
|
+
render << "</select></div>"
|
113
|
+
render
|
114
|
+
end
|
115
|
+
|
116
|
+
def render_canvas(text,style)
|
117
|
+
text
|
118
|
+
end
|
119
|
+
|
120
|
+
def render_hrule(text,style)
|
121
|
+
"<h />"
|
122
|
+
end
|
123
|
+
$fieldset_was_already_opened = false
|
124
|
+
def render_fieldset(text,style)
|
125
|
+
myStyle = HtmlStyle.new
|
126
|
+
myStyle["width"] = style["width"].to_i - 20
|
127
|
+
myStyle["height"] = style["height"].to_i - 20
|
128
|
+
response = ""
|
129
|
+
response << "</fieldset>" if $fieldset_was_already_opened
|
130
|
+
response << "<fieldset style=\"height: " + myStyle["height"].to_s + "; width: " + myStyle["width"].to_s + "\"><legend>" + text + "</legend>"
|
131
|
+
$fieldset_was_already_opened = true
|
132
|
+
response
|
133
|
+
end
|
134
|
+
|
135
|
+
def render_textarea(text,style)
|
136
|
+
"<textarea>"+text+"</textarea>"
|
137
|
+
end
|
138
|
+
|
139
|
+
def render_formattingtoolbar(text,style)
|
140
|
+
"<img src=\"images/formattingtoolbar.png\" />"
|
141
|
+
end
|
142
|
+
|
143
|
+
def render_checkbox(text,style)
|
144
|
+
text+" <INPUT TYPE=CHECKBOX NAME=\""+text+"\">"
|
145
|
+
end
|
146
|
+
|
147
|
+
def render_stickynote(text,style)
|
148
|
+
"<div style=\"width: 100%; height: 100%;background-color: yellow;\"><b>Sticky note</b><br />"+text+"</div>"
|
149
|
+
end
|
150
|
+
|
151
|
+
def export
|
152
|
+
@output_content = "<html><body>"
|
153
|
+
i = 1
|
154
|
+
@doc.root.each_element('//control') { |control|
|
155
|
+
color = make_color
|
156
|
+
type = control.attributes["controlTypeID"].gsub!(/com.balsamiq.mockups::/,'').to_s.downcase
|
157
|
+
text = ""
|
158
|
+
left = control.attributes["x"]
|
159
|
+
top = control.attributes["y"]
|
160
|
+
width = control.attributes["w"]
|
161
|
+
if width.to_i == -1 and width.to_i < control.attributes["measuredW"].to_i
|
162
|
+
width = control.attributes["measuredW"]
|
163
|
+
end
|
164
|
+
height = control.attributes["h"]
|
165
|
+
if height.to_i == -1 and height.to_i < control.attributes["measuredH"].to_i
|
166
|
+
height = control.attributes["measuredH"]
|
167
|
+
end
|
168
|
+
zindex = control.attributes["zOrder"]
|
169
|
+
|
170
|
+
style = HtmlStyle.new
|
171
|
+
style["left"] = left
|
172
|
+
style["top"] = top
|
173
|
+
style["width"] = width
|
174
|
+
style["height"] = height
|
175
|
+
|
176
|
+
# begin
|
177
|
+
unless control[1].nil? or control[1][1].nil? or control[1][1].text.nil?
|
178
|
+
text = control[1][1].text.url_decode
|
179
|
+
end
|
180
|
+
@output_content << "<div style=\"border: 0px black solid; background-color:"+"; position:absolute; z-index:"+zindex+';'+
|
181
|
+
"left:"+left+"px;"+
|
182
|
+
"top:"+top+"px;"+
|
183
|
+
"width:"+width+"px;"+
|
184
|
+
"height:"+height+"px;"+
|
185
|
+
"\">"+render(type,format(text),style)+"</div><br />\n" unless width.nil? or height.nil?
|
186
|
+
# rescue Exception => e
|
187
|
+
# p "Control removed: "+control.to_s+" because "+e.message
|
188
|
+
# end
|
189
|
+
i += 1
|
190
|
+
}
|
191
|
+
|
192
|
+
@output_content += "</body></html>"
|
193
|
+
end
|
194
|
+
|
195
|
+
def save
|
196
|
+
File.open(@output, 'w') {|f| f.write(@output_content) }
|
197
|
+
end
|
198
|
+
|
199
|
+
def export!
|
200
|
+
export
|
201
|
+
save
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bmmlexporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Franck Verrot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-07 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Bmmlexporter provides simple Balsamiq Mockup .bmml files exporting features.
|
17
|
+
email: franck@verrot.fr
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- lib/bmmlexporter.rb
|
27
|
+
- lib/bmmlhtmlexporter.rb
|
28
|
+
- History.txt
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://home.dev-fr.com
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project: bmmlexporter
|
51
|
+
rubygems_version: 1.3.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Bmmlexporter provides simple Balsamiq Mockup .bmml files exporting features.
|
55
|
+
test_files: []
|
56
|
+
|