2 # $Id: app.rb 30 2005-04-23 15:25:21Z 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")
69 Eet::File.open(@options.output, "w") do |ef|
83 OptionParser.new do |o|
84 o.banner = "Usage: redact [options] INPUT_FILE"
87 o.separator "Specific options:"
89 o.on("-o", "--output OUTPUT_FILE",
90 "Write Edje to OUTPUT_FILE") do |file|
91 @options.output = file
94 o.on("--image_dir IMAGE_DIR",
95 "Add IMAGE_DIR to the image lookup path") do |dir|
96 @options.image_dir = dir
99 o.on("--font_dir FONT_DIR",
100 "Add FONT_DIR to the font lookup path") do |dir|
101 @options.font_dir = dir
105 o.separator "Common options:"
107 o.on_tail("-h", "--help", "Show this message") do
112 o.on_tail("--version", "Show version") do
113 puts "Redact #{Redact::VERSION}"
124 EDJE.collections.each_value do |col|
125 next unless col.has_embryo?
127 Tempfile.open("redact_col#{col.id}.sma") do |tf_in|
128 tf_in.puts "#include <edje>"
132 Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
133 incl = `edje-config --datadir`.strip
136 "-i #{incl}/include " +
137 "-o #{tf_out.path} #{tf_in.path}"
139 raise("Cannot compile Embryo code")
142 ret[col.id] = tf_out.read
150 def dump_sma(tf, col)
151 if col.has_embryo?(false)
152 tf.puts col.script.to_embryo(col)
155 col.programs.each_value do |p|
156 next unless p.is_a?(ExecScriptProgram)
158 s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1")
161 public _p#{p.id}(sig[], src[])
169 def dump_amx(amx, ef)
170 amx.each do |id, code|
171 ef.write("scripts/#{id}", code)
176 ef.write("edje_file", EDJE.to_eet)
179 def dump_collections(ef)
180 EDJE.collections.each_value do |col|
181 ef.write("collections/#{col.id}", col.to_eet)
186 EDJE.font_dir.each do |entry|
187 ef.write("fonts/#{entry.filename}",
188 File.read(entry.filename))
193 EDJE.image_dir.each do |entry|
194 ef.write_image("images/#{entry.id}",
195 entry.image.data_for_reading_only,
196 entry.image.width, entry.image.height,
197 entry.image.has_alpha?)
204 SCRIPT_LINES__.each do |file, value|
205 sane = Pathname.new(file).cleanpath.to_s
206 method = (sane == @filename) ? :unshift : :push
207 s.send(method, SourceFile.new(sane, value.join))
209 # include files that are read with File.read, too
210 value.join.grep(/File\.read\(\"(.+)\"\)/) do
211 sane = Pathname.new($1).cleanpath.to_s
212 s << SourceFile.new(sane, File.read(sane))
216 ef.write("edje_sources", s.to_eet)
220 fm = EDJE.font_dir.inject(FontMap.new) do |a, entry|
221 a << FontMapEntry.new(entry)
224 ef.write("edje_source_fontmap", fm.to_eet)