Class: Tipsy::Handler::PhpProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tipsy/handler/php.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(d) ⇒ PhpProcessor

Returns a new instance of PhpProcessor.



27
28
29
30
31
32
33
# File 'lib/tipsy/handler/php.rb', line 27

def initialize(d)
  @data  = d
  @cname = nil
  unless Dir.exists?(compile_to)
    FileUtils.mkdir(compile_to)
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



25
26
27
# File 'lib/tipsy/handler/php.rb', line 25

def data
  @data
end

#envObject

Returns the value of attribute env.



25
26
27
# File 'lib/tipsy/handler/php.rb', line 25

def env
  @env
end

#templateObject

Returns the value of attribute template.



25
26
27
# File 'lib/tipsy/handler/php.rb', line 25

def template
  @template
end

Instance Method Details

#cache_nameObject



39
40
41
# File 'lib/tipsy/handler/php.rb', line 39

def cache_name
  @cname ||= ::Digest::MD5.hexdigest(template.gsub(File.join(Tipsy.root, 'views'), ''))
end

#compile_toObject



35
36
37
# File 'lib/tipsy/handler/php.rb', line 35

def compile_to
  File.join(Tipsy.root, '.php-temp')
end

#renderObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tipsy/handler/php.rb', line 47

def render
  # if File.exists?(tempfile) && (File.mtime(tempfile) > File.mtime(template))
  #   return File.read(tempfile)
  # end
  puts "PARSE TEMPLATE #{template}"
  File.open(tempfile, 'w') do |file|
    file.puts(@data)
  end
  ``
  res = `php #{tempfile}`
  puts res.to_s
  res.to_s
end

#tempfileObject



43
44
45
# File 'lib/tipsy/handler/php.rb', line 43

def tempfile
  File.join(compile_to, "#{cache_name}.php")
end