2 # $Id: app.rb 1 2005-03-26 01:32:38Z tilman $
4 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 require "redact/redact.rb"
26 require "redact/source.rb"
38 @options = OpenStruct.new
39 @option_parser = parse_args(args)
41 @options.input = args.first
42 if @options.input.nil?
43 puts @option_parser.help
47 @options.output ||= @options.input.sub(/.[^.]+$/, ".edj")
57 raise("Cannot load '#{@options.input}'")
60 @filename = Pathname.new(@options.input).cleanpath.to_s
62 if EDJE.collections.empty?
63 raise("No collections found")
68 Eet::File.open(@options.output, "w") do |ef|
82 OptionParser.new do |o|
83 o.banner = "Usage: redact [options] INPUT_FILE"
86 o.separator "Specific options:"
88 o.on("-o", "--output OUTPUT_FILE",
89 "Write Edje to OUTPUT_FILE") do |file|
90 @options.output = file
93 o.on("--image_dir IMAGE_DIR",
94 "Add IMAGE_DIR to the image lookup path") do |dir|
95 @options.image_dir = dir
98 o.on("--font_dir FONT_DIR",
99 "Add FONT_DIR to the font lookup path") do |dir|
100 @options.font_dir = dir
104 o.separator "Common options:"
106 o.on_tail("-h", "--help", "Show this message") do
111 o.on_tail("--version", "Show version") do
113 redact #{Redact::VERSION}
115 Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
127 EDJE.collections.each_value do |col|
128 next unless col.has_embryo?
130 File.open("/tmp/redact.sma", "w") do |tf|
131 tf.puts "#include <edje>"
135 out = "/tmp/redact.amx"
138 incl = `edje-config --datadir`.strip
140 "-i #{incl}/include " +
141 "-o #{out} #{tf.path}"
144 ret[col.id] = IO.read(out)
153 def dump_sma(tf, col)
154 if col.has_embryo?(false)
155 tf.puts col.script.to_embryo(col)
158 col.programs.each_value do |p|
159 next unless p.is_a?(ExecScriptProgram)
161 s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1")
164 public _p#{p.id}(sig[], src[])
172 def dump_amx(amx, ef)
173 amx.each do |id, code|
174 ef.write("scripts/#{id}", code)
179 ef.write("edje_file", EDJE.to_eet)
182 def dump_collections(ef)
183 EDJE.collections.each_value do |col|
184 ef.write("collections/#{col.id}", col.to_eet)
189 EDJE.font_dir.each do |entry|
190 ef.write("fonts/#{entry.filename}",
191 File.read(entry.filename))
196 EDJE.image_dir.each do |entry|
197 ef.write_image("images/#{entry.id}",
198 entry.image.data_for_reading_only,
199 entry.image.width, entry.image.height,
200 entry.image.has_alpha?)
207 SCRIPT_LINES__.each do |file, value|
208 sane = Pathname.new(file).cleanpath.to_s
209 method = (sane == @filename) ? :unshift : :push
210 s.send(method, SourceFile.new(sane, value.join))
212 # include files that are with File.read, too
213 value.join.grep(/File\.read\(\"(.+)\"\)/) do
214 sane = Pathname.new($1).cleanpath.to_s
215 s << SourceFile.new(sane, File.read(sane))
219 ef.write("edje_sources", s.to_eet)
223 fm = EDJE.font_dir.inject(FontMap.new) do |a, entry|
224 a << FontMapEntry.new(entry)
227 ef.write("edje_source_fontmap", fm.to_eet)