2 # $Id: app.rb 40 2005-05-25 20:19:45Z 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"
39 @options = OpenStruct.new
40 @option_parser = parse_args(args)
42 @options.input = args.first
43 if @options.input.nil?
44 puts @option_parser.help
48 @options.output ||= @options.input.sub(/.[^.]+$/, ".edj")
58 raise("Cannot load '#{@options.input}'")
61 @filename = Pathname.new(@options.input).cleanpath.to_s
63 if EDJE.collections.empty?
64 raise("No collections found")
70 Eet::File.open(@options.output, "w") do |ef|
81 File.rm_f(@options.output)
88 OptionParser.new do |o|
89 o.banner = "Usage: redact [options] INPUT_FILE"
92 o.separator "Specific options:"
94 o.on("-o", "--output OUTPUT_FILE",
95 "Write Edje to OUTPUT_FILE") do |file|
96 @options.output = file
99 o.on("--image_dir IMAGE_DIR",
100 "Add IMAGE_DIR to the image lookup path") do |dir|
101 @options.image_dir = dir
104 o.on("--font_dir FONT_DIR",
105 "Add FONT_DIR to the font lookup path") do |dir|
106 @options.font_dir = dir
110 o.separator "Common options:"
112 o.on_tail("-h", "--help", "Show this message") do
117 o.on_tail("--version", "Show version") do
118 puts "Redact #{Redact::VERSION}"
129 EDJE.collections.each_value do |col|
130 next unless col.has_embryo?
132 Tempfile.open("redact_col#{col.id}.sma") do |tf_in|
133 tf_in.puts "#include <edje>"
137 Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
138 incl = `edje-config --datadir`.strip
141 "-i #{incl}/include " +
142 "-o #{tf_out.path} #{tf_in.path}"
144 unless (0..1).include?($?.exitstatus)
145 raise("Cannot compile Embryo code")
148 ret[col.id] = tf_out.read
156 def dump_sma(tf, col)
157 if col.has_embryo?(false)
158 tf.puts col.script.to_embryo(col)
161 col.programs.each_value do |p|
162 next unless p.is_a?(ExecScriptProgram)
164 s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1")
167 public _p#{p.id}(sig[], src[])
175 def dump_amx(amx, ef)
176 amx.each do |id, code|
177 ef.write("scripts/#{id}", code)
182 ef.write("edje_file", EDJE.to_eet)
185 def dump_collections(ef)
186 EDJE.collections.each_value do |col|
187 ef.write("collections/#{col.id}", col.to_eet)
192 EDJE.font_dir.each do |entry|
193 ef.write("fonts/#{entry.filename}",
194 File.read(entry.filename))
199 EDJE.image_dir.each do |entry|
200 ef.write_image("images/#{entry.id}",
201 entry.image.data_for_reading_only,
202 entry.image.width, entry.image.height,
203 entry.image.has_alpha?)
210 SCRIPT_LINES__.each do |file, value|
211 sane = Pathname.new(file).cleanpath.to_s
212 method = (sane == @filename) ? :unshift : :push
213 s.send(method, SourceFile.new(sane, value.join))
215 # include files that are read with File.read, too
216 value.join.grep(/File\.read\(\"(.+)\"\)/) do
217 sane = Pathname.new($1).cleanpath.to_s
218 s << SourceFile.new(sane, File.read(sane))
222 ef.write("edje_sources", s.to_eet)
226 fm = EDJE.font_dir.inject(FontMap.new) do |a, entry|
227 a << FontMapEntry.new(entry)
230 ef.write("edje_source_fontmap", fm.to_eet)