Class: Semantic::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/semantic/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_flash_messagesObject



46
47
48
# File 'lib/generators/semantic/install_generator.rb', line 46

def copy_flash_messages
  copy_file 'shared/_messages.html.erb', 'app/views/shared/_messages.html.erb', force: true
end

#copy_scaffold_viewsObject



35
36
37
38
39
40
# File 'lib/generators/semantic/install_generator.rb', line 35

def copy_scaffold_views
  %w[edit index show new].each do |file|
    template "scaffolds/#{options[:template_engine]}/#{file}.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/#{file}.html.#{options[:template_engine]}", force: true
  end
  copy_file "scaffolds/#{options[:template_engine]}/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}", force: true
end

#copy_shared_paginationObject



50
51
52
# File 'lib/generators/semantic/install_generator.rb', line 50

def copy_shared_pagination
  copy_file("shared/_pagination.html.#{options[:template_engine]}", "app/views/shared/_pagination.html.#{options[:template_engine]}", force: true) if options[:pagination]
end

#copy_simpleformsObject



54
55
56
57
58
59
# File 'lib/generators/semantic/install_generator.rb', line 54

def copy_simpleforms
  if options[:simpleform]
    copy_file 'initializers/simple_form.rb', 'config/initializers/simple_form.rb', force: true
    copy_file "simple_form/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}", force: true
  end
end

#create_layoutObject



42
43
44
# File 'lib/generators/semantic/install_generator.rb', line 42

def create_layout
  template("layouts/application.html.#{options[:template_engine]}.tt", "app/views/layouts/application.html.#{options[:template_engine]}", force: true) if options[:layout]
end

#inject_helpersObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/generators/semantic/install_generator.rb', line 61

def inject_helpers
  pagy_helper = (options[:pagination] ? 'include Pagy::Frontend' : '')
  helper_str = <<~HELPER
  #{pagy_helper}
    # For generating SemanitcUI based flash[:notices]
    def flash_class(level)
      case level
      when 'success'
        'positive'
      when 'error'
        'negative'
      when 'alert'
        'negative'
      when 'notice'
        'info'
      else
        'info'
      end
    end
HELPER
  inject_into_file 'app/helpers/application_helper.rb', optimize_indentation(helper_str,2), after: "module ApplicationHelper\n", force: true
end

#invoke_devise_generatorObject



84
85
86
87
# File 'lib/generators/semantic/install_generator.rb', line 84

def invoke_devise_generator
  # Generate semantic based devise views if devise is being used
  invoke('semantic:devise') if options[:devise]
end