Class: Erb::Generators::LeoscaGenerator

Inherits:
ScaffoldGenerator
  • Object
show all
Includes:
Leonardo::Leosca, Leonardo::Nested
Defined in:
lib/generators/erb/leosca/leosca_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_view_filesObject

override



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

def copy_view_files
  available_views.each do |view|
    filenames = filenames_all_formats(view, source_paths)
    filenames.each do |filename|
      #Looking for custom filename into subfolder
      filename_source = "#{"formtastic/" if formtastic?}#{filename}"
      search_into_subfolder = nil
      source_paths.each do |path|
        if File.exists?(File.join(path,filename_source))
          search_into_subfolder = true
          break
        end
      end
      filename_source = filename unless search_into_subfolder

      template filename_source, File.join("app/views", base_namespaces, controller_file_path, filename)
    end
  end
end

#update_layout_htmlObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/erb/leosca/leosca_generator.rb', line 40

def update_layout_html
  file = "app/views/layouts/_#{CONFIG[:default_style]}.html.erb"
  if nested?
    inject_into_file file, :before => "            <!-- Insert above here other #{last_parent} elements -->" do
      <<-FILE.gsub(/^              /, '')
                    #{"<% if can?(:read, #{class_name}) && controller.controller_path == '#{controller_name}' -%>" if authorization?}
                    <li class="active"><%= t('models.#{plural_table_name}') %></li>
                    <!-- Insert above here other #{singular_table_name} elements -->
                    #{"<% end -%>" if authorization?}
      FILE
    end if File.exists?(file)
  #elsif leospaced?
  #  inject_into_file file, :before => "            <!-- Insert above other elements -->" do
  #    <<-FILE.gsub(/^              /, '')
  #                  #{"<% if #{options.auth_class}_signed_in? && current_#{options.auth_class}.role?(#{last_namespace.inspect}) -%>" if authorization?}
  #                  <li class="<%= controller.controller_path == '#{last_namespace}' ? 'active' : '' %>"><a href="<%= #{last_namespace}_index_path %>">#{last_namespace.capitalize}</a></li>
  #                  <!-- Insert above here other #{last_namespace} elements -->
  #                  #{"<% end -%>" if authorization?}
  #    FILE
  #  end if File.exists?(file)
  #  inject_into_file file, :before => "            <!-- Insert above other elements -->" do
  #    <<-FILE.gsub(/^              /, '')
  #                  #{"<% if can?(:read, #{class_name}) -%>" if authorization?}
  #                  <li class="<%= controller.controller_path == '#{formatted_namespace_path}#{controller_name}' ? 'active' : '' %>"><a href="<%= #{list_resources_path} %>"><%= t('models.#{plural_table_name}') %></a></li>
  #                  <!-- Insert above here other #{singular_table_name} elements -->
  #                  #{"<% end -%>" if authorization?}
  #    FILE
  #  end if File.exists?(file)
  else
    inject_into_file file, :before => "            <!-- Insert above other elements -->" do
      <<-FILE.gsub(/^            /, '')
                  #{"<% if can?(:read, #{class_name}) -%>" if authorization?}
                  <li class="<%= controller.controller_path == '#{formatted_namespace_path}#{controller_name}' ? 'active' : '' %>"><a href="<%= #{list_resources_path} %>"><%= t('models.#{plural_table_name}') %></a></li>
                  <!-- Insert above here other #{singular_table_name} elements -->
                  #{"<% end -%>" if authorization?}
      FILE
    end if File.exists?(file)
  end
end

#update_parent_viewsObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/generators/erb/leosca/leosca_generator.rb', line 80

def update_parent_views
  return unless nested?
  file = "app/views/#{plural_last_parent}/_row_index.html.erb"
  inject_into_file file, :before => "<!-- Manage section, do not remove this tag -->" do
    <<-FILE.gsub(/^          /, '')
    <td><%= link_to t('models.#{plural_table_name}'), #{list_resources_path_back} %></td>

    FILE
  end if File.exists?(file)
end