class Ate

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Constants

VERSION

Public Class Methods

build_proc(lines, vars) click to toggle source
# File lib/ate.rb, line 33
def build_proc(lines, vars)
  @output = "Proc.new do \n output = \"\" \n "
  declaring_local_variables(vars)
  parsing_lines(lines)
  @output << "output \n end"
end
declaring_local_variables(vars) click to toggle source
# File lib/ate.rb, line 40
def declaring_local_variables(vars)
  vars.each do |x, y|
    value = y.is_a?(String) ? "\"#{y}\"" : y
    @output << "#{x} = #{value}\n"
  end
end
parse(template, vars = {}) click to toggle source
# File lib/ate.rb, line 24
def parse(template, vars = {})
  context = vars.fetch(:context, self)
  lines = template.end_with?(".ate") ? File.read(template) : template
  lines = lines.split("\n")
  built = build_proc(lines, vars)
  @parsed = context.instance_eval(built)
  self
end
parsing_lines(lines) click to toggle source
# File lib/ate.rb, line 47
def parsing_lines(lines)
  lines.each do |line|
    if line =~ /^\s*(%)(.*?)$/
      @output << "#{line.gsub(/^\s*%(.*?)$/, '\1') } \n"
    else
      @output << "output << %Q|#{line.gsub(/\{\{([^\r\n]*)\}\}/, '#{\1}')}\n| \n "
    end
  end
end
render() click to toggle source
# File lib/ate.rb, line 57
def render
  @parsed.call
end