class Locomotive::Wagon::Generators::Section
Constants
- ICON_LIST
Public Class Methods
source_root()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 88 def self.source_root File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'section') end
Public Instance Methods
build_options()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 39 def build_options @_slug = slug.clone.downcase.gsub(/[-]/, '_') @options = { name: @_slug.humanize, type: @_slug, global: @global, icon: @icon, settings: extract_section_settings, blocks: extra_blocks, all_icons: ICON_LIST } end
create_javascript_file()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 58 def create_javascript_file if File.exists?(sections_js_path) js_class_name = @options[:type].classify file_path = File.join(sections_js_path, @options[:type]) template "%type%.js.tt", "#{file_path}.js", @options append_to_file File.join(sections_js_path, 'index.js'), <<-JS export { default as #{js_class_name} } from './#{@options[:type]}'; JS insert_into_file 'app/assets/javascripts/app.js', after: "// Register sections here. DO NOT REMOVE OR UPDATE THIS LINE\n" do " sectionsManager.registerSection('#{@options[:type]}', Sections.#{js_class_name});\n" end end end
create_section()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 52 def create_section # create the liquid file file_path = File.join(sections_path, @_slug) template "template.liquid.tt", "#{file_path}.liquid", @options end
create_stylesheet_file()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 75 def create_stylesheet_file if File.exists?(sections_css_path) css_class_name = "#{@options[:type].dasherize}-section" file_path = File.join(sections_css_path, @options[:type]) template "%type%.scss.tt", "#{file_path}.scss", @options insert_into_file 'app/assets/stylesheets/app.scss', after: "// Register sections here. DO NOT REMOVE OR UPDATE THIS LINE\n" do "@import 'sections/#{@options[:type]}';\n" end end end
is_global?()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 26 def is_global? if (@global = self.options[:global]).nil? @global = yes?('Is this section aimed to be used as global (same content for all the pages)?') end end
which_icon?()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 32 def which_icon? if (@icon = self.options[:icon]).nil? question = 'Which icon should be displayed in the editor UI?' @icon = ask(question, limited_to: ICON_LIST) end end
Protected Instance Methods
default_block_settings()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 138 def default_block_settings [ BlockSetting.new('list_item', 'title', 'text', 'Item title'), BlockSetting.new('list_item', 'image', 'image_picker', 'Item image') ] end
default_section_settings()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 131 def default_section_settings [ SectionSetting.new('title', 'text', 'My awesome title'), SectionSetting.new('image', 'image_picker', 'An image') ] end
extra_blocks()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 115 def extra_blocks # build block settings _settings = settings.map do |raw_setting| next unless raw_setting.starts_with?('block:') # block setting _, block_type, id, type = raw_setting.split(':') BlockSetting.new(block_type, id, type) end.compact.presence || [] if settings.blank? _settings = default_block_settings end # group them by block types _settings.group_by { |setting| setting.block_type } end
extract_section_settings()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 106 def extract_section_settings # build section settings only settings.map do |raw_setting| next if raw_setting.starts_with?('block:') # block setting id, type = raw_setting.split(':') SectionSetting.new(id, type) end.compact.presence || default_section_settings end
sections_css_path()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 102 def sections_css_path File.join(target_path, 'app', 'assets', 'stylesheets', 'sections') end
sections_js_path()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 98 def sections_js_path File.join(target_path, 'app', 'assets', 'javascripts', 'sections') end
sections_path()
click to toggle source
# File lib/locomotive/wagon/generators/section.rb, line 94 def sections_path File.join(target_path, 'app', 'views', 'sections') end