Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/internal/filemode/embed_filemode.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
perm1 = File.stat(File.join(__DIR__, "template", "file1.ecr")).perm
perm2 = File.stat(File.join(__DIR__, "template", "file2")).perm
perm1 = File.info(File.join(__DIR__, "template", "file1.ecr")).permissions
perm2 = File.info(File.join(__DIR__, "template", "file2")).permissions
puts <<-EOS
FILE1_PERM = #{perm1}
FILE2_PERM = #{perm2}
FILE1_PERM = File::Permissions.from_value(#{perm1.value})
FILE2_PERM = File::Permissions.from_value(#{perm2.value})
EOS
8 changes: 4 additions & 4 deletions spec/internal/filemode_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module TeeplateInternalSpecs::Executable
file1 = File.join(tmp, "file1")
file2 = File.join(tmp, "file2")
Template.new.render tmp, force: true
File.stat(file1).perm.should eq FILE1_PERM
File.stat(file2).perm.should eq FILE2_PERM
File.info(file1).permissions.should eq FILE1_PERM
File.info(file2).permissions.should eq FILE2_PERM
end
end

Expand All @@ -30,8 +30,8 @@ module TeeplateInternalSpecs::Executable
File.write file2, ""
File.chmod file2, 0o666
Template.new.render tmp, force: true
File.stat(file1).perm.should eq FILE1_PERM
File.stat(file2).perm.should eq FILE2_PERM
File.info(file1).permissions.should eq FILE1_PERM
File.info(file2).permissions.should eq FILE2_PERM
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/lib/base64_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Teeplate
getter path : String
getter size : UInt64
getter encoded : String
getter perm : UInt32
getter perm : File::Permissions
getter? forces : Bool

def initialize(@path, @size, @encoded, perm : Int::Primitive = 0o644, force = false)
@perm = perm.to_u32
def initialize(@path, @size, @encoded, perm : File::Permissions = File::Permissions.from_value(0o644), force = false)
@perm = perm
@forces = force
end

Expand Down
10 changes: 3 additions & 7 deletions src/lib/file_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ module Teeplate
getter absolute_path : String
getter path : String
getter size : UInt64
getter perm : UInt32
getter perm : File::Permissions
getter? forces : Bool

def initialize(@absolute_path, @path, size : UInt64? = nil, perm : Int::Primitive? = nil, force = false)
def initialize(@absolute_path, @path, size : UInt64? = nil, perm : File::Permissions? = nil, force = false)
@size = size || File.size(@absolute_path)
@perm = if perm
perm.to_u32
else
File.stat(@absolute_path).perm.to_u32
end
@perm = perm || File.info(@absolute_path).permissions
@forces = force
end

Expand Down
7 changes: 3 additions & 4 deletions src/lib/file_entry_collector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ module Teeplate

def each_file(abs, rel, &block : String, String ->)
Dir.open(abs) do |d|
d.each do |entry|
if entry != "." && entry != ".."
each_file abs, rel, entry, &block
end
d.each_child do |entry|
each_file abs, rel, entry, &block
end
end
end
Expand All @@ -27,6 +25,7 @@ module Teeplate
end

@entries : Array(AsDataEntry)?

def entries
@entries ||= begin
a = [] of AsDataEntry
Expand Down
12 changes: 5 additions & 7 deletions src/lib/file_tree/macros/directory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ require "base64"

def each_file(abs, rel, &block : String, String ->)
Dir.open(abs) do |d|
d.each do |entry|
if entry != "." && entry != ".."
each_file abs, rel, entry, &block
end
d.each_child do |entry|
each_file abs, rel, entry, &block
end
end
end
Expand All @@ -32,22 +30,22 @@ def pack_ecr(i, sb, abs, rel)
STDOUT << <<-EOS
\nio = IO::Memory.new
__ecr#{i} io
____files << ::Teeplate::StringData.new("#{rel}", io.to_s, #{File.stat(abs).perm})
____files << ::Teeplate::StringData.new("#{rel}", io.to_s, File::Permissions.from_value(#{File.info(abs).permissions.value}))
EOS
end

def pack_blob(sb, abs, rel)
STDOUT << "\n____files << ::Teeplate::Base64Data.new(\"#{rel}\", "
io = IO::Memory.new
File.open(abs){|f| IO.copy(f, io)}
File.open(abs) { |f| IO.copy(f, io) }
if io.size > 0
STDOUT << "#{io.size}_u64, <<-EOS\n"
Base64.encode io, STDOUT
STDOUT << "EOS\n"
else
STDOUT << "0_u64, \"\""
end
STDOUT << ", #{File.stat(abs).perm})"
STDOUT << ", File::Permissions.from_value(#{File.info(abs).permissions.value}))"
end

STDOUT << "def ____collect_files(____files)"
Expand Down
15 changes: 9 additions & 6 deletions src/lib/rendering_entry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Teeplate
end

@out_path : String?

# Returns an output location.
#
# It makes an absolute location with the renderer's setting and this entry's local path.
Expand All @@ -30,16 +31,17 @@ module Teeplate
end

@local_path : String?

# Returns an output path relative to the base location.
#
# It returns the data entry's path by default.
# Override this method if this path should be different from the data entry's path.
def local_path
@local_path ||= if appends?
@data.path[1..-1]
else
@data.path
end
@data.path[1..-1]
else
@data.path
end
end

# :nodoc:
Expand Down Expand Up @@ -112,6 +114,7 @@ module Teeplate
end

@action : Symbol?

# :nodoc:
def action
@action ||= get_action
Expand Down Expand Up @@ -200,9 +203,9 @@ module Teeplate
end
begin
if !GIT.empty?
Process.new(GIT, ["diff", "--no-index", "--", out_path, "-"], shell: true, input: r, output: true, error: true).wait
Process.new(GIT, ["diff", "--no-index", "--", out_path, "-"], shell: true, input: r, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit).wait
elsif !DIFF.empty?
Process.new(DIFF, ["-u", out_path, "-"], shell: true, input: r, output: true, error: true).wait
Process.new(DIFF, ["-u", out_path, "-"], shell: true, input: r, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit).wait
else
STDOUT.puts "No diff command is installed."
end
Expand Down
6 changes: 3 additions & 3 deletions src/lib/string_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module Teeplate

getter path : String
getter string : String
getter perm : UInt32
getter perm : File::Permissions
getter? forces : Bool

def initialize(@path, @string, perm : Int::Primitive = 0o644, force = false)
@perm = perm.to_u32
def initialize(@path, @string, perm : File::Permissions = File::Permissions.from_value(0o644), force = false)
@perm = perm
@forces = force
end

Expand Down