Class: Grass::Key

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Validations, ActiveModel::Validations::Callbacks
Defined in:
lib/grass/key.rb

Overview

Key parses path info into template meta data

Constant Summary collapse

KEY_REGEX =
{
  locale: /\/([a-z]{2}|[a-z]{2}\-[A-Z]{2})\//,      
  dir: /\/(views\/layouts|views)\/|\/(scripts|stylesheets|images|fonts|statics)\/|\/(pages|texts)\//,      
  path: /\/([\w|\-|\/]+)/,
  ext: /\.(:?[a-z]{1,})/
}
FILE_REGEX =
{
  # dir: /\/(views\/layouts|views)\/|\/assets\/(scripts|stylesheets|statics)\/|\/content\/(pages|texts)\//,
  dir: /\/(views\/layouts|views)\/|\/(scripts|stylesheets|images|fonts|statics)\/|\/(pages|texts)\//,            
  path: /\/([\w|\-|\/]+)/,
  locale: /\.([a-z]{2}|[a-z]{2}\-[A-Z]{2})\./,
  ext: /\.(:?[a-z]{1,})/
}
ATTR_TYPES =
[:id, :dir, :path, :locale, :format, :handler, :filepath]
FORMATS =
{
  'texts'          => 'txt',
  'views'          => 'html',
  'views/layouts'  => 'html',
  'pages'          => 'html',
  'scripts'        => 'js',
  'stylesheets'    => 'css'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Key

before_validation :parse



46
47
48
49
# File 'lib/grass/key.rb', line 46

def initialize attributes = {}
  super(attributes)
  parse()
end

Instance Method Details

#fullpathObject



59
60
61
# File 'lib/grass/key.rb', line 59

def fullpath
  @fullpath ||= @dir =~ /pages/ ? "/#{@locale}/#{@dir}/#{@path}" : "/#{@locale}/#{@dir}/#{@path}.#{@format}"
end

#serializable_hashObject



51
52
53
# File 'lib/grass/key.rb', line 51

def serializable_hash
  {id: self.id, dir: dir, path: path, locale: locale, format: format, handler: handler, filepath: filepath}
end

#to_sObject



55
56
57
# File 'lib/grass/key.rb', line 55

def to_s
  self.id
end