Sha256: 7a4a8a3fa465d89da881107eda279f88092a0fabbf8cc48a37fe192213dedd73

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Nanoc2

  # A Nanoc2::Template represents a template, which can be used for creating
  # new pages. Pages don't necessary have to be created using templates, but
  # they can be useful for generating pages where you only have to "fill in
  # the blanks".
  class Template

    # The Nanoc2::Site this template belongs to.
    attr_accessor :site

    # The name of this template.
    attr_reader :name

    # The raw content a page created using this template will have.
    attr_reader :page_content

    # A hash containing the attributes a page created using this template will
    # have.
    attr_reader :page_attributes

    # Creates a new template.
    #
    # +name+:: The name of this template.
    #
    # +page_content+:: The raw content a page created using this template will
    #                  have.
    #
    # +page_attributes+:: A hash containing the attributes a page created
    #                     using this template will have.
    def initialize(page_content, page_attributes, name)
      @page_content     = page_content
      @page_attributes  = page_attributes.clean
      @name             = name
    end

    # Saves the template in the database, creating it if it doesn't exist yet
    # or updating it if it already exists. Tells the site's data source to
    # save the template.
    def save
      @site.data_source.loading do
        @site.data_source.save_template(self)
      end
    end

    # Renames the template. Tells the site's data source to rename the
    # template.
    def move_to(new_name)
      @site.data_source.loading do
        @site.data_source.move_template(self, new_name)
      end
    end

    # Deletes the template. Tells the site's data source to delete the
    # template.
    def delete
      @site.data_source.loading do
        @site.data_source.delete_template(self)
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc2-2.2.3 lib/nanoc2/base/template.rb