2 # $Id: app.rb 57 2005-06-14 15:11:35Z 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"
42 OPTIONS = OpenStruct.new
50 @option_parser = parse_args(args)
52 OPTIONS.input = args.first
54 puts @option_parser.help
58 OPTIONS.output ||= OPTIONS.input.sub(/.[^.]+$/, ".edj")
68 raise("Cannot load '#{OPTIONS.input}'")
71 @filename = Pathname.new(OPTIONS.input).cleanpath.to_s
73 if EDJE.collections.empty?
74 raise("No collections found")
80 Eet::File.open(OPTIONS.output, "w") do |ef|
91 File.rm_f(OPTIONS.output)
98 OptionParser.new do |o|
99 o.banner = "Usage: redact [options] INPUT_FILE"
102 o.separator "Specific options:"
104 o.on("-o", "--output OUTPUT_FILE",
105 "Write Edje to OUTPUT_FILE") do |file|
106 OPTIONS.output = file
109 o.on("--image_dir IMAGE_DIR",
110 "Add IMAGE_DIR to the image lookup path") do |dir|
111 OPTIONS.image_dir = dir
114 o.on("--font_dir FONT_DIR",
115 "Add FONT_DIR to the font lookup path") do |dir|
116 OPTIONS.font_dir = dir
120 o.separator "Common options:"
122 o.on_tail("-h", "--help", "Show this message") do
127 o.on_tail("--version", "Show version") do
128 puts "Redact #{Redact::VERSION}"
139 EDJE.collections.each_value do |col|
140 next unless col.has_embryo?
142 Tempfile.open("redact_col#{col.id}.sma") do |tf_in|
143 tf_in.puts "#include <edje>"
147 Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
148 incl = `edje-config --datadir`.strip
151 "-i #{incl}/include " +
152 "-o #{tf_out.path} #{tf_in.path}"
154 unless (0..1).include?($?.exitstatus)
155 raise("Cannot compile Embryo code")
158 ret[col.id] = tf_out.read
166 def dump_sma(tf, col)
167 if col.has_embryo?(false)
168 tf.puts col.script.to_embryo(col)
171 col.programs.each_value do |p|
172 next unless p.is_a?(ExecScriptProgram)
174 s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1")
177 public _p#{p.id}(sig[], src[])
185 def dump_amx(amx, ef)
186 amx.each do |id, code|
187 ef.write("scripts/#{id}", code)
192 ef.write("edje_file", EDJE.to_eet)
195 def dump_collections(ef)
196 EDJE.collections.each_value do |col|
197 ef.write("collections/#{col.id}", col.to_eet)
202 EDJE.font_dir.each do |entry|
203 ef.write("fonts/#{entry.alias}",
204 File.read(entry.filename))
209 EDJE.image_dir.each do |entry|
210 ef.write_image("images/#{entry.id}",
211 entry.image.data_for_reading_only,
212 entry.image.width, entry.image.height,
213 entry.image.has_alpha?)
220 SCRIPT_LINES__.each do |file, value|
221 sane = Pathname.new(file).cleanpath.to_s
222 method = (sane == @filename) ? :unshift : :push
223 s.send(method, SourceFile.new(sane, value.join))
225 # include files that are read with File.read, too
226 value.join.grep(/File\.read\(\"(.+)\"\)/) do
227 sane = Pathname.new($1).cleanpath.to_s
228 s << SourceFile.new(sane, File.read(sane))
232 ef.write("edje_sources", s.to_eet)
236 fm = EDJE.font_dir.inject(FontMap.new) do |a, entry|
237 a << FontMapEntry.new(entry)
240 ef.write("edje_source_fontmap", fm.to_eet)