Sha256: 43e54fbba7b79dc324a6054fae8f0fa0bdc7c44121ae5949569f3da905dae471

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

module SitemapGenerator
  # Provide convenient access to template files.  E.g.
  #
  #   SitemapGenerator.templates.sitemap_index
  #
  # Lazy-load and cache for efficient access.
  # Define an accessor method for each template file.
  class Templates
    FILES = {
      :sitemap_sample =>  'sitemap.rb',
    }

    # Dynamically define accessors for each key defined in <tt>FILES</tt>
    attr_accessor(*FILES.keys)
    FILES.keys.each do |name|
      eval <<-END
        define_method(:#{name}) do
          @#{name} ||= read_template(:#{name})
        end
      END
    end

    def initialize(root = SitemapGenerator.root)
      @root = root
    end

    # Return the full path to a template.
    #
    # <tt>file</tt> template symbol e.g. <tt>:sitemap_sample</tt>
    def template_path(template)
      File.join(@root, 'templates', self.class::FILES[template])
    end

    protected

    # Read the template file and return its contents.
    def read_template(template)
      File.read(template_path(template))
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sitemap_generator-6.3.0/lib/sitemap_generator/templates.rb
sitemap_generator-6.3.0 lib/sitemap_generator/templates.rb
sitemap_generator-6.2.1 lib/sitemap_generator/templates.rb
sitemap_generator-6.2.0 lib/sitemap_generator/templates.rb
sitemap_generator-6.1.2 lib/sitemap_generator/templates.rb
sitemap_generator-6.1.1 lib/sitemap_generator/templates.rb
sitemap_generator-6.1.0 lib/sitemap_generator/templates.rb
sitemap_generator-6.0.2 lib/sitemap_generator/templates.rb