Sha256: e9d0098c24e672371480c0b029bc80199c93318c2134e257a727aa0ecf511164
Contents?: true
Size: 1.32 KB
Versions: 22
Compression:
Stored size: 1.32 KB
Contents
module TypeStation class DSL def self.build(name, options = {}, &block) Page.new(name, options).call(&block) end class Page attr_reader :model def initialize(title, options = {}, parent = nil) @title = title @options = options @parent = parent @model = _build_model(@title, @options, @parent) end def call(&block) if block_given? if block.arity == 1 block.call model else instance_eval &block end end model end def page(name, options = {}, &block) Page.new(name, options, model).call(&block) end private def _build_model(title, options, parent) parent_id = parent ? parent.id : nil name = options[:name] template_name = options[:template] || (parent ? title.parameterize('_') : 'index') redirect_to = options[:redirect_to] slug = options[:slug] status = options[:status] || ::TypeStation::Page::STATUS.last model = ::TypeStation::Page.create(title: title, name: name, template_name: template_name, status: status, redirect_to: redirect_to, parent_id: parent_id) if slug.present? model.slug = slug model.save end model end end end end
Version data entries
22 entries across 22 versions & 1 rubygems