class Effective::Generators::MenuGenerator

Public Instance Methods

create_admin_menu() click to toggle source

layouts/_navbar_admin.html.haml

# File lib/generators/effective/menu_generator.rb, line 47
def create_admin_menu
  return unless resource.namespaces == ['admin']

  begin
    Effective::CodeWriter.new(resource.admin_menu_file) do |w|
      if w.find { |line, _| line == menu_content.second.strip }
        say_status :identical, menu_path, :blue
      else
        if (w.insert_into_first(menu_content) { |line, _| line.include?('.navbar-nav') })
          say_status :menu, menu_path, :green
        else
          say_status(:skipped, :menu, :yellow)
        end
      end
    end
  rescue Errno::ENOENT
    # This will raise an error if the navbar file isn't present
    say_status :skipped, :menu, :yellow
  end
end
create_menu() click to toggle source

layouts/_navbar.html.haml

# File lib/generators/effective/menu_generator.rb, line 25
def create_menu
  return unless resource.namespaces.blank?

  begin
    Effective::CodeWriter.new(resource.menu_file) do |w|
      if w.find { |line, _| line == menu_content.second.strip }
        say_status :identical, menu_path, :blue
      else
        if (w.insert_into_first(menu_content) { |line, _| line.include?('.navbar-nav') })
          say_status :menu, menu_path, :green
        else
          say_status(:skipped, :menu, :yellow)
        end
      end
    end
  rescue Errno::ENOENT
    # This will raise an error if the navbar file isn't present
    say_status :skipped, :menu, :yellow
  end
end
invoke_menu() click to toggle source
# File lib/generators/effective/menu_generator.rb, line 20
def invoke_menu
  say_status :invoke, :menu, :white
end
validate_resource() click to toggle source
# File lib/generators/effective/menu_generator.rb, line 16
def validate_resource
  exit unless resource_valid?
end

Private Instance Methods

menu_content() click to toggle source
menu_path() click to toggle source