Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
cache partial names to not include multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Quang Le committed Jan 28, 2016
1 parent 3c0f124 commit 9c0f865
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/wolverine/script.rb
Expand Up @@ -78,21 +78,25 @@ def relative_path
end

def load_lua file
TemplateContext.template(file)
TemplateContext.new.template(file)
end

class TemplateContext

def self.template(pathname)

def template(pathname)
@partial_templates ||= {}
ERB.new(File.read(pathname)).result binding
end

# helper method to include a lua partial within another lua script
#
# @param relative_path [String] the relative path to the script from
# @param relative_path [String] the relative path to the script from
# `Wolverine.config.script_path`
def self.include_partial(relative_path)
template( Pathname.new("#{Wolverine.config.script_path}/#{relative_path}") )
def include_partial(relative_path)
unless @partial_templates.has_key? relative_path
@partial_templates[relative_path] = nil
template( Pathname.new("#{Wolverine.config.script_path}/#{relative_path}") )
end
end
end

Expand Down

0 comments on commit 9c0f865

Please sign in to comment.