Class: Frozen::Template::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/frozen/template/base.rb

Direct Known Subclasses

Javascript, Stylesheet, View

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



6
7
8
# File 'lib/frozen/template/base.rb', line 6

def file_path
  @file_path
end

#template_root_pathObject

Returns the value of attribute template_root_path.



7
8
9
# File 'lib/frozen/template/base.rb', line 7

def template_root_path
  @template_root_path
end

Instance Method Details

#build_extensionObject



58
59
60
# File 'lib/frozen/template/base.rb', line 58

def build_extension
  ".html"
end

#build_file_pathObject



41
42
43
44
# File 'lib/frozen/template/base.rb', line 41

def build_file_path
  File.join(build_path,relative_path,build_filename)
    .sub(/^[\/\.]+/,'')
end

#build_filenameObject



33
34
35
36
37
38
39
# File 'lib/frozen/template/base.rb', line 33

def build_filename
  filename = File.basename(file_path, ".#{file_type}")
  unless File.extname(filename) == build_extension
    filename << build_extension
  end
  filename
end

#build_pathObject



53
54
55
# File 'lib/frozen/template/base.rb', line 53

def build_path
  ""
end

#file_typeObject



63
64
65
# File 'lib/frozen/template/base.rb', line 63

def file_type
  File.extname(file_path)[1..-1]
end

#read_from_file(file) ⇒ Object



9
10
11
12
# File 'lib/frozen/template/base.rb', line 9

def read_from_file(file)
  @file_path = file
  File.read(file)
end

#relative_pathObject



15
16
17
18
19
20
21
22
23
# File 'lib/frozen/template/base.rb', line 15

def relative_path
  return "" unless template_root_path
  pn_template_root_path = Pathname.new(template_root_path)
  pn_file_path = Pathname.new(file_path)
  val = pn_file_path.relative_path_from(pn_template_root_path)
    .dirname.to_s
  val = "" if val == "."
  val
end

#relative_to_rootObject



46
47
48
49
50
51
# File 'lib/frozen/template/base.rb', line 46

def relative_to_root
  Pathname.new(".")
    .relative_path_from(Pathname.new(relative_path))
    .to_s
    .sub(/^\/\./,'')
end

#render_to_file(file) ⇒ Object



26
27
28
29
30
31
# File 'lib/frozen/template/base.rb', line 26

def render_to_file(file)
  unless Dir.exist?(File.dirname(file))
    FileUtils.mkdir_p(File.dirname(file))
  end
  File.write(file, render)
end

#template_filenameObject



67
68
69
# File 'lib/frozen/template/base.rb', line 67

def template_filename
  File.basename(file_path)
end

#template_pathObject



71
72
73
# File 'lib/frozen/template/base.rb', line 71

def template_path
  File.dirname(file_path)
end