Class: Tipsy::Handler::PhpProcessor
- Inherits:
-
Object
- Object
- Tipsy::Handler::PhpProcessor
- Defined in:
- lib/tipsy/handler/php.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#env ⇒ Object
Returns the value of attribute env.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #cache_name ⇒ Object
- #compile_to ⇒ Object
-
#initialize(d) ⇒ PhpProcessor
constructor
A new instance of PhpProcessor.
- #render ⇒ Object
- #tempfile ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
25 26 27 |
# File 'lib/tipsy/handler/php.rb', line 25 def data @data end |
#env ⇒ Object
Returns the value of attribute env.
25 26 27 |
# File 'lib/tipsy/handler/php.rb', line 25 def env @env end |
#template ⇒ Object
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_name ⇒ Object
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_to ⇒ Object
35 36 37 |
# File 'lib/tipsy/handler/php.rb', line 35 def compile_to File.join(Tipsy.root, '.php-temp') end |
#render ⇒ Object
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 |
#tempfile ⇒ Object
43 44 45 |
# File 'lib/tipsy/handler/php.rb', line 43 def tempfile File.join(compile_to, "#{cache_name}.php") end |