Module: Rake::Templates

Defined in:
lib/rake/templates.rb,
lib/rake/templates/context.rb,
lib/rake/templates/version.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.allObject



15
16
17
18
19
20
21
22
# File 'lib/rake/templates.rb', line 15

def all
  Dir["templates/**/*"].map do |file|
    path = Pathname.new(file)
    next if path.directory?
    next if path.to_s =~ /^_/
    path
  end.compact
end

.cleanObject



51
52
53
54
# File 'lib/rake/templates.rb', line 51

def clean
  public.rmtree if public.exist?
  public.mkpath unless public.exist?
end

.compile(file) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rake/templates.rb', line 24

def compile(file)
  public.mkpath unless public.exist?

  template = Tilt.new(file.to_s)
  context = Context.new
  rendered_content = template.render(context)
  path = result_path(template)
  path.open("w") do |f|
    f << rendered_content
  end
end

.compile_allObject



45
46
47
48
49
# File 'lib/rake/templates.rb', line 45

def compile_all
  all.each do |file|
    compile file
  end
end

.publicObject



11
12
13
# File 'lib/rake/templates.rb', line 11

def public
  Pathname.new("public")
end

.result_path(template) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rake/templates.rb', line 36

def result_path(template)
  extra_endings = template.file.split(".")[2..-1].join(".")
  dirname = File.dirname(template.file).gsub(/^templates/, "public")
  basename = template.basename(".#{extra_endings}")
  dir = Pathname.new(dirname)
  dir.mkpath
  dir.join(basename)
end