Class: QuickSearch::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_javascriptObject



125
126
127
# File 'lib/generators/quick_search/install_generator.rb', line 125

def add_javascript
  gsub_file('app/assets/javascripts/application.js', '//= require_tree .', '//= require quick_search')
end

#add_stylesObject



119
120
121
122
# File 'lib/generators/quick_search/install_generator.rb', line 119

def add_styles
  remove_file 'app/assets/stylesheets/application.css'
  create_file 'app/assets/stylesheets/application.css.scss', %Q|@import "quick_search";\n|
end

#best_bets_ymlObject



109
110
111
# File 'lib/generators/quick_search/install_generator.rb', line 109

def best_bets_yml
  copy_file 'best_bets.yml', 'config/best_bets.yml'
end

#bundle_install_theme_searchersObject



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

def bundle_install_theme_searchers
  Bundler.with_clean_env do
    run "bundle install"
  end
end

#configuration_messagesObject



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/generators/quick_search/install_generator.rb', line 136

def configuration_messages
  say "QuickSearch installation complete.\n\n", :green
  if @searcher_response == 'y'
    say "We've installed a set of default searchers.\n", :green
  end
  if @theme_response == 'y'
    say "We've installed the generic theme.\n", :green
  end
  file = File.read(File.join( File.expand_path('../templates', __FILE__), 'post_install.txt'))
  say file, :green
end

#insert_routesObject



7
8
9
10
11
12
# File 'lib/generators/quick_search/install_generator.rb', line 7

def insert_routes
  routes = <<-ROUTES
  mount QuickSearch::Engine => "/"
ROUTES
  insert_into_file "config/routes.rb", routes, :after => "Rails.application.routes.draw do\n"
end

#insert_searchersObject



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
79
# File 'lib/generators/quick_search/install_generator.rb', line 47

def insert_searchers
  searcher_gem_entry = <<-SEARCHERS
\n
# -Inserted by QuickSearch-

# QuickSearch searchers
#
# If you want to use different searchers, remove/replace these and be sure to remove them from
# your config/quick_search_config.yml file as well as references to them in your theme's search
# results page template

gem 'quick_search-wikipedia_searcher'
gem 'quick_search-open_library_searcher'
gem 'quick_search-arxiv_searcher'
gem 'quick_search-placeholder_searcher'

# -END Inserted by QuickSearch-

  SEARCHERS

  say("\nTo have a working application you'll need to install some searchers. Searchers are the
code that integrates with third-party APIs, handles performing searches and creating results objects.
By default quick_search-core provides no searchers. Some searchers are available and it is easy to
write your own.\n\n")


  @searcher_response = ask("Would you like to install some basic searchers that do not require API keys?", limited_to: ['y', 'n'])

  if @searcher_response == 'y'
    insert_into_file "Gemfile", searcher_gem_entry, :after => /gem [\"\']quick_search-core[\"\'].*$/
  end

end

#insert_themeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/quick_search/install_generator.rb', line 16

def insert_theme

  theme_gem_entry = <<-THEME
\n
# -Inserted by QuickSearch-

# QuickSearch theme
#
# Remove the following if you want to use a different theme

gem 'quick_search-generic_theme'

# END -Inserted by QuickSearch-

THEME


  say("\nYou'll need to include a theme which QuickSearch uses to render your results. We've built a generic
theme which can be modified or extended to meet your needs. Alternatively you can build your own from
scratch and include it.\n\n")

  @theme_response = ask("Would you like to install the generic theme?", limited_to: ['y', 'n'])

  if @theme_response == 'y'
    insert_into_file "Gemfile", theme_gem_entry, :after => /gem [\"\']quick_search-core[\"\'].*$/
  end

end

#install_migrationsObject



130
131
132
133
# File 'lib/generators/quick_search/install_generator.rb', line 130

def install_migrations
  rake "quick_search:install:migrations"
  rake "db:migrate"
end

#kaminari_initializerObject



114
115
116
# File 'lib/generators/quick_search/install_generator.rb', line 114

def kaminari_initializer
  copy_file 'kaminari.rb', 'config/initializers/kaminari.rb'
end

#quick_search_config_ymlObject



90
91
92
# File 'lib/generators/quick_search/install_generator.rb', line 90

def quick_search_config_yml
  copy_file 'quick_search_config.yml', 'config/quick_search_config.yml'
end

#update_quick_search_configObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/generators/quick_search/install_generator.rb', line 95

def update_quick_search_config
  if @theme_response == 'y'
    theme_config = 'quick_search_generic_theme'
    insert_into_file "config/quick_search_config.yml", theme_config, :after => /^  theme: '/
  end
  if @searcher_response == 'y'
    included_searchers = ',arxiv,open_library,wikipedia,placeholder'
    included_found_types = 'arxiv,open_library,wikipedia,placeholder,placeholder,placeholder,placeholder'
    insert_into_file "config/quick_search_config.yml", included_searchers, :after => /^  searchers: \[best_bets/
    insert_into_file "config/quick_search_config.yml", included_found_types, :after => /^  found_types: \[/
  end
end