Sha256: 34fe94851dd7b6e7313b09fa0851eba99eaa79feb005cb57991cf6fc7959a3bc

Contents?: true

Size: 909 Bytes

Versions: 5

Compression:

Stored size: 909 Bytes

Contents

module HighVoltage
  class Page
    attr_reader :content_path, :file_path

    def initialize(content_path, file_path)
      @content_path = content_path
      @file_path = file_path
    end

    def id
      file_path.gsub(content_path, "").split(".").first
    end

    def valid?
      exists? && file_in_content_path? && !directory? && !partial? && handled?
    end

    private

    def handler_extension
      File.extname(file_path).delete(".")
    end

    def exists?
      File.exist?(file_path)
    end

    def file_in_content_path?
      file_path.start_with?(content_path)
    end

    def directory?
      FileTest.directory?(file_path)
    end

    def partial?
      File.basename(file_path).first == "_"
    end

    def handled?
      available_handlers.include? handler_extension
    end

    def available_handlers
      ActionView::Template.template_handler_extensions
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
high_voltage-4.0.0 lib/high_voltage/page.rb
high_voltage-4.0.0.rc1 lib/high_voltage/page.rb
high_voltage-3.1.2 lib/high_voltage/page.rb
high_voltage-3.1.1 lib/high_voltage/page.rb
high_voltage-3.1.0 lib/high_voltage/page.rb