Sha256: 0b5d8e995ffefb649d2fdc1815ce6b8666572738c0a6abea04e1e598fb28745e
Contents?: true
Size: 1.42 KB
Versions: 28
Compression:
Stored size: 1.42 KB
Contents
require File.join(__FILE__, '../../base') module Alchemy module Generators class ElementsGenerator < Base desc "This generator generates your elements view partials." source_root File.expand_path('templates', File.dirname(__FILE__)) def create_directory @elements_dir = "#{Rails.root}/app/views/alchemy/elements" empty_directory @elements_dir end def create_partials @elements = load_alchemy_yaml('elements.yml') @elements.each do |element| @element = element if @element['available_contents'] @available_contents_names = @element['available_contents'].collect { |c| c['name'] } @contents = (element["contents"].delete_if { |c| @available_contents_names.include?(c['name']) } or []) else @contents = (element["contents"] or []) end if element["name"] =~ /\A[a-z0-9_-]+\z/ @element_name = element["name"].underscore else raise "Element name '#{element['name']}' has wrong format. Only lowercase and non whitespace characters allowed." end conditional_template "editor.html.#{template_engine}", "#{@elements_dir}/_#{@element_name}_editor.html.#{template_engine}" conditional_template "view.html.#{template_engine}", "#{@elements_dir}/_#{@element_name}_view.html.#{template_engine}" end if @elements end end end end
Version data entries
28 entries across 28 versions & 1 rubygems