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_effective_menus ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/effective/menu_generator.rb', line 41

def create_effective_menus
  begin
    Effective::CodeWriter.new('lib/tasks/generate/effective_menus.rake') do |w|
      if w.find { |line, _| line == effective_menus_content }
        say_status :identical, resource.index_path, :blue
      else
        index = w.first { |line, _| line.start_with?('item') }

        w.insert(effective_menus_content, index)

        system('rake generate:effective_menus')

        say_status :effective_menus, resource.plural_name + '_path', :green
      end
    end
  rescue Errno::ENOENT
    # This will raise an error if the navbar file isn't present
    say_status :skipped, :effective_menus, :yellow
  end
end

#create_menu ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/effective/menu_generator.rb', line 19

def create_menu
  begin
    Effective::CodeWriter.new((['app/views'] + resource.namespaces + ['_navbar.html.haml']).join('/')) do |w|
      if w.find { |line, _| line == menu_content.last.strip }
        say_status :identical, resource.index_path, :blue
      else
        index = w.last { |line, _| line.start_with?('- if can?') }

        if index.blank?
          say_status(:skipped, :menu, :yellow) and return
        end

        w.insert_raw(menu_content, index+1, w.depth_at(index))
        say_status :menu, resource.index_path, :green
      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 ⇒ Object



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

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