Class: Effective::Generators::MenuGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/effective/menu_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_admin_menuObject

layouts/_navbar_admin.html.haml



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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_menuObject

layouts/_navbar.html.haml



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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_menuObject



20
21
22
# File 'lib/generators/effective/menu_generator.rb', line 20

def invoke_menu
  say_status :invoke, :menu, :white
end

#validate_resourceObject



16
17
18
# File 'lib/generators/effective/menu_generator.rb', line 16

def validate_resource
  exit unless resource_valid?
end