Class: Zwite::App

Inherits:
Object show all
Defined in:
lib/zwite/core/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, path, url) ⇒ App

Initialization



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zwite/core/app.rb', line 38

def initialize(site, path, url)
  self.site = site
  self.path = path
  self.url = url
  self.static_url = self.url + "static/"
  self.name = self.path.basename.to_s
  self.output_path = self.site.output_path + self.url[1..self.url.length]
  self.plugins = []
  self.site.plugins.each do |p|
    plugin = p.new(self)
    if plugin.enabled?
      self.plugins << plugin
    end
  end
  self.liquid_file_system = Zwite::Liquid::FileSystem.new((self.path + "templates").to_s)
end

Instance Attribute Details

#liquid_file_systemObject

Returns the value of attribute liquid_file_system.



16
17
18
# File 'lib/zwite/core/app.rb', line 16

def liquid_file_system
  @liquid_file_system
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/zwite/core/app.rb', line 13

def name
  @name
end

#output_pathObject

Returns the value of attribute output_path.



14
15
16
# File 'lib/zwite/core/app.rb', line 14

def output_path
  @output_path
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/zwite/core/app.rb', line 10

def path
  @path
end

#pluginsObject

Returns the value of attribute plugins.



15
16
17
# File 'lib/zwite/core/app.rb', line 15

def plugins
  @plugins
end

#siteObject

Properties



9
10
11
# File 'lib/zwite/core/app.rb', line 9

def site
  @site
end

#static_urlObject

Returns the value of attribute static_url.



12
13
14
# File 'lib/zwite/core/app.rb', line 12

def static_url
  @static_url
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/zwite/core/app.rb', line 11

def url
  @url
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/zwite/core/app.rb', line 63

def eql?(other)
  return self.path.eql?(other.path)
end

#generateObject



73
74
75
76
77
# File 'lib/zwite/core/app.rb', line 73

def generate
  self.plugins.each do |p|
    p.generate
  end
end

#hashObject

Actions



59
60
61
# File 'lib/zwite/core/app.rb', line 59

def hash
  return self.path.hash
end

#preprocessObject



67
68
69
70
71
# File 'lib/zwite/core/app.rb', line 67

def preprocess
  self.plugins.each do |p|
    p.preprocess
  end
end

#render(contents, context = {}, path = nil, validate = true) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/zwite/core/app.rb', line 79

def render(contents, context = {}, path = nil, validate = true)
  ::Liquid::Template.file_system = self.liquid_file_system
  template = ::Liquid::Template.parse(contents)
  ctx = self.site.liquid_context
  ctx = ctx.merge_recursive(context)
  
  output = template.render(ctx)
  
  # # nokogiri validate
  # if validate
  #   n = Nokogiri.parse(output)
  #   if n.errors.any?
  #     message = ["\n"]
  #     unless path.nil?
  #       message << "[VALIDATION ERROR]: #{path}"
  #       
  #     else
  #       message << "[VALIDATION ERROR]"
  #     end
  #     n.errors.each do |error|
  #       message << "\tline: #{error.line} error: #{error}"
  #     end
  #     
  #     message << "\n\n"
  #     raise message.join("\n")
  #     
  #   end
  # end
  
  return output
end

#render_file(path, context = {}) ⇒ Object



111
112
113
114
# File 'lib/zwite/core/app.rb', line 111

def render_file(path, context = {})
  contents = path.read
  return render(contents, context, path)
end

#render_template(template, context = {}) ⇒ Object



116
117
118
# File 'lib/zwite/core/app.rb', line 116

def render_template(template, context = {})
  return render_file((self.path + "templates" + template), context)
end

#to_liquidObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zwite/core/app.rb', line 22

def to_liquid
  hash = {
    "url" => self.url,
    "static_url" => self.static_url,
    "name" => self.name
  }
  self.plugins.each do |p|
    hash[p.name] = p
  end
  return hash
end

#to_sObject



18
19
20
# File 'lib/zwite/core/app.rb', line 18

def to_s
  return "<Zwite::App> name: #{self.name}, mount: #{self.url}"
end