Sha256: 1a0ded488506521f54b2ea0011cc92a5c11c4df8d78e1c39476c7243ab1835e8

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

# Curly is a simple view system. Each view consists of two parts, a
# template and a presenter. The template is a simple string that can contain
# references in the format `{{refname}}`, e.g.
#
#   Hello {{recipient}},
#   you owe us ${{amount}}.
#
# The references will be converted into messages that are sent to the
# presenter, which is any Ruby object. Only public methods can be referenced.
# To continue the earlier example, here's the matching presenter:
#
#   class BankPresenter
#     def initialize(recipient, amount)
#       @recipient, @amount = recipient, amount
#     end
#
#     def recipient
#       @recipient.full_name
#     end
#
#     def amount
#       "%.2f" % @amount
#     end
#   end
#
# See Curly::Presenter for more information on presenters.
#
module Curly
  VERSION = "1.0.1"

  # Compiles a Curly template to Ruby code.
  #
  # template - The template String that should be compiled.
  #
  # Returns a String containing the Ruby code.
  def self.compile(template, presenter_class)
    Compiler.compile(template, presenter_class)
  end

  # Whether the Curly template is valid. This includes whether all
  # references are available on the presenter class.
  #
  # template        - The template String that should be validated.
  # presenter_class - The presenter Class.
  #
  # Returns true if the template is valid, false otherwise.
  def self.valid?(template, presenter_class)
    Compiler.valid?(template, presenter_class)
  end
end

require 'curly/compiler'
require 'curly/presenter'
require 'curly/template_handler'
require 'curly/railtie' if defined?(Rails)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
curly-templates-1.0.1 lib/curly.rb