Class: Grass::Key
- Inherits:
-
Object
- Object
- Grass::Key
- 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
- #fullpath ⇒ Object
-
#initialize(attributes = {}) ⇒ Key
constructor
before_validation :parse.
- #serializable_hash ⇒ Object
- #to_s ⇒ Object
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
#fullpath ⇒ Object
59 60 61 |
# File 'lib/grass/key.rb', line 59 def fullpath @fullpath ||= @dir =~ /pages/ ? "/#{@locale}/#{@dir}/#{@path}" : "/#{@locale}/#{@dir}/#{@path}.#{@format}" end |
#serializable_hash ⇒ Object
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_s ⇒ Object
55 56 57 |
# File 'lib/grass/key.rb', line 55 def to_s self.id end |