Sha256: 4e7563f2bca906f3f7f99dc619ff7def90a4921298e135cd647eeaf7568ae041

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'fileutils'

module Frozen
  module Template
    class Base
      attr_accessor :file_path
      attr_accessor :template_root_path

      def read_from_file(file)
        @file_path = file
        File.read(file)
      end


      def relative_path
        return "" unless template_root_path
        pn_template_root_path = Pathname.new(template_root_path)
        pn_file_path = Pathname.new(file_path)
        val = pn_file_path.relative_path_from(pn_template_root_path)
          .dirname.to_s
        val = "" if val == "."
        val
      end


      def render_to_file(file)
        unless Dir.exist?(File.dirname(file))
          FileUtils.mkdir_p(File.dirname(file))
        end
        File.write(file, render)
      end

      def build_filename
        filename = File.basename(file_path, ".#{file_type}")
        unless File.extname(filename) == build_extension
          filename << build_extension
        end
        filename
      end

      def build_file_path
        File.join(build_path,relative_path,build_filename)
          .sub(/^[\/\.]+/,'')
      end

      def relative_to_root
        Pathname.new(".")
          .relative_path_from(Pathname.new(relative_path))
          .to_s
          .sub(/^\/\./,'')
      end

      def build_path
        ""
      end


      def build_extension
        ".html"
      end


      def file_type
        File.extname(file_path)[1..-1]
      end

      def template_filename
        File.basename(file_path)
      end

      def template_path
        File.dirname(file_path)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frozen-0.0.1 lib/frozen/template/base.rb