projects
/
redact.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added Description#inherit.
[redact.git]
/
lib
/
redact
/
app.rb
diff --git
a/lib/redact/app.rb
b/lib/redact/app.rb
index de666280863078905bb9af53c69b31c1b9d34338..5a229100b1a3b9f8d22919851c1dcf5c9fdbb37b 100644
(file)
--- a/
lib/redact/app.rb
+++ b/
lib/redact/app.rb
@@
-1,5
+1,5
@@
#--
#--
-# $Id: app.rb
1 2005-03-26 01:32:38
Z tilman $
+# $Id: app.rb
57 2005-06-14 15:11:35
Z tilman $
#
# Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
#
#
# Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
#
@@
-25,26
+25,37
@@
require "redact/redact.rb"
require "redact/source.rb"
require "ftools"
require "redact/redact.rb"
require "redact/source.rb"
require "ftools"
+require "tempfile"
require "pathname"
require "ostruct"
require "optparse"
SCRIPT_LINES__ = {}
require "pathname"
require "ostruct"
require "optparse"
SCRIPT_LINES__ = {}
+class OpenStruct
+ def clear
+ @table = {}
+ end
+end
+
module Redact
module Redact
+ OPTIONS = OpenStruct.new
+
class App
class App
+ attr_reader :options
+
def initialize(args)
@filename = nil
def initialize(args)
@filename = nil
- @options = OpenStruct.new
+ OPTIONS.clear
@option_parser = parse_args(args)
@option_parser = parse_args(args)
-
@options
.input = args.first
- if
@options
.input.nil?
+
OPTIONS
.input = args.first
+ if
OPTIONS
.input.nil?
puts @option_parser.help
exit
end
puts @option_parser.help
exit
end
-
@options.output ||= @options
.input.sub(/.[^.]+$/, ".edj")
+
OPTIONS.output ||= OPTIONS
.input.sub(/.[^.]+$/, ".edj")
end
def run
end
def run
@@
-52,12
+63,12
@@
module Redact
SCRIPT_LINES__.clear
begin
SCRIPT_LINES__.clear
begin
- load
@options
.input
+ load
OPTIONS
.input
rescue LoadError
rescue LoadError
- raise("Cannot load '#{
@options
.input}'")
+ raise("Cannot load '#{
OPTIONS
.input}'")
end
end
- @filename = Pathname.new(
@options
.input).cleanpath.to_s
+ @filename = Pathname.new(
OPTIONS
.input).cleanpath.to_s
if EDJE.collections.empty?
raise("No collections found")
if EDJE.collections.empty?
raise("No collections found")
@@
-65,15
+76,20
@@
module Redact
amx = compile_embryo
amx = compile_embryo
- Eet::File.open(@options.output, "w") do |ef|
- dump_amx(amx, ef)
-
- dump_header(ef)
- dump_collections(ef)
- dump_fonts(ef)
- dump_images(ef)
- dump_source(ef)
- dump_fontmap(ef)
+ begin
+ Eet::File.open(OPTIONS.output, "w") do |ef|
+ dump_amx(amx, ef)
+
+ dump_header(ef)
+ dump_collections(ef)
+ dump_fonts(ef)
+ dump_images(ef)
+ dump_source(ef)
+ dump_fontmap(ef)
+ end
+ rescue Exception
+ File.rm_f(OPTIONS.output)
+ raise
end
end
end
end
@@
-87,17
+103,17
@@
module Redact
o.on("-o", "--output OUTPUT_FILE",
"Write Edje to OUTPUT_FILE") do |file|
o.on("-o", "--output OUTPUT_FILE",
"Write Edje to OUTPUT_FILE") do |file|
-
@options
.output = file
+
OPTIONS
.output = file
end
o.on("--image_dir IMAGE_DIR",
"Add IMAGE_DIR to the image lookup path") do |dir|
end
o.on("--image_dir IMAGE_DIR",
"Add IMAGE_DIR to the image lookup path") do |dir|
-
@options
.image_dir = dir
+
OPTIONS
.image_dir = dir
end
o.on("--font_dir FONT_DIR",
"Add FONT_DIR to the font lookup path") do |dir|
end
o.on("--font_dir FONT_DIR",
"Add FONT_DIR to the font lookup path") do |dir|
-
@options
.font_dir = dir
+
OPTIONS
.font_dir = dir
end
o.separator ""
end
o.separator ""
@@
-109,11
+125,7
@@
module Redact
end
o.on_tail("--version", "Show version") do
end
o.on_tail("--version", "Show version") do
- puts <<EOT
-redact #{Redact::VERSION}
-
-Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
-EOT
+ puts "Redact #{Redact::VERSION}"
exit
end
exit
end
@@
-127,23
+139,24
@@
EOT
EDJE.collections.each_value do |col|
next unless col.has_embryo?
EDJE.collections.each_value do |col|
next unless col.has_embryo?
-
File.open("/tmp/redact.sma", "w") do |tf
|
- tf.puts "#include <edje>"
- dump_sma(tf, col)
- tf.flush
+
Tempfile.open("redact_col#{col.id}.sma") do |tf_in
|
+ tf
_in
.puts "#include <edje>"
+ dump_sma(tf
_in
, col)
+ tf
_in
.flush
- out = "/tmp/redact.amx"
- File.rm_f(out)
+ Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
+ incl = `edje-config --datadir`.strip
- incl = `edje-config --datadir`.strip
- c = "embryo_cc " +
- "-i #{incl}/include " +
- "-o #{out} #{tf.path}"
- system(c)
+ c = "embryo_cc " +
+ "-i #{incl}/include " +
+ "-o #{tf_out.path} #{tf_in.path}"
+ system(c)
+ unless (0..1).include?($?.exitstatus)
+ raise("Cannot compile Embryo code")
+ end
- ret[col.id] = IO.read(out)
- File.rm_f(out)
- File.unlink(tf.path)
+ ret[col.id] = tf_out.read
+ end
end
end
end
end
@@
-187,7
+200,7
@@
EOT
def dump_fonts(ef)
EDJE.font_dir.each do |entry|
def dump_fonts(ef)
EDJE.font_dir.each do |entry|
- ef.write("fonts/#{entry.
filename
}",
+ ef.write("fonts/#{entry.
alias
}",
File.read(entry.filename))
end
end
File.read(entry.filename))
end
end
@@
-209,7
+222,7
@@
EOT
method = (sane == @filename) ? :unshift : :push
s.send(method, SourceFile.new(sane, value.join))
method = (sane == @filename) ? :unshift : :push
s.send(method, SourceFile.new(sane, value.join))
- # include files that are with File.read, too
+ # include files that are
read
with File.read, too
value.join.grep(/File\.read\(\"(.+)\"\)/) do
sane = Pathname.new($1).cleanpath.to_s
s << SourceFile.new(sane, File.read(sane))
value.join.grep(/File\.read\(\"(.+)\"\)/) do
sane = Pathname.new($1).cleanpath.to_s
s << SourceFile.new(sane, File.read(sane))