Class: Liquid::LocalFileSystem

### Home Classes Methods

### In Files

- lib/liquid/file_system.rb

### Parent

Object

### Methods

- ::new
- #full_path
- #read_template_file

### Class/Module Index

Quicksearch

- Liquid
- Liquid::ArgumentError
- Liquid::Assign
- Liquid::BlankFileSystem
- Liquid::Block
- Liquid::Break
- Liquid::BreakInterrupt
- Liquid::Capture
- Liquid::Case
- Liquid::Comment
- Liquid::Context
- Liquid::ContextError
- Liquid::Continue
- Liquid::ContinueInterrupt
- Liquid::Cycle
- Liquid::Decrement
- Liquid::Document
- Liquid::Drop
- Liquid::ElseCondition
- Liquid::Error
- Liquid::FileSystemError
- Liquid::FilterNotFound
- Liquid::For
- Liquid::If
- Liquid::Ifchanged
- Liquid::Include
- Liquid::Increment
- Liquid::Interrupt
- Liquid::LocalFileSystem
- Liquid::MemoryError
- Liquid::Raw
- Liquid::StackLevelError
- Liquid::StandardError
- Liquid::StandardFilters
- Liquid::SyntaxError
- Liquid::TableRow
- Liquid::Tag
- Liquid::Template
- Liquid::Unless
- Liquid::Utils
- Liquid::Variable
- FalseClass
- LiquidView
- Module
- NilClass
- TrueClass

No matching classes.

# Liquid::LocalFileSystem

This implements an abstract file system which retrieves template files named in a manner similar to Rails partials, ie. with the template name prefixed with an underscore. The extension ".liquid" is also added.

For security reasons, template paths are only allowed to contain letters, numbers, and underscore.

Example:

file_system = Liquid::LocalFileSystem.new("/some/path")

file_system.full_path("mypartial") # => "/some/path/_mypartial.liquid" file_system.full_path("dir/mypartial") # => "/some/path/dir/_mypartial.liquid"

### Attributes

root[RW]

### Public Class Methods

new(root) click to toggle source

    # File lib/liquid/file_system.rb, line 37
    def initialize(root)
      @root = root
    end

### Public Instance Methods

full_path(template_path) click to toggle source

    # File lib/liquid/file_system.rb, line 48
    def full_path(template_path)
      raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/

      full_path = if template_path.include?('/')
        File.join(root, File.dirname(template_path), "_#{File.basename(template_path)}.liquid")
      else
        File.join(root, "_#{template_path}.liquid")
      end

      raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /^#{File.expand_path(root)}/

      full_path
    end

read_template_file(template_path, context) click to toggle source

    # File lib/liquid/file_system.rb, line 41
    def read_template_file(template_path, context)
      full_path = full_path(template_path)
      raise FileSystemError, "No such template '#{template_path}'" unless File.exists?(full_path)

      File.read(full_path)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.