Class: Thesis::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Thesis::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/thesis/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #complete_message ⇒ Object
- #copy_migrations ⇒ Object
- #create_folders ⇒ Object
- #install_css ⇒ Object
- #install_js ⇒ Object
- #install_page_is_editable ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/generators/thesis/install/install_generator.rb', line 12 def self.next_migration_number(path) unless @prev_migration_nr @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i else @prev_migration_nr += 1 end @prev_migration_nr.to_s end |
Instance Method Details
#complete_message ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/thesis/install/install_generator.rb', line 84 def require "thesis/colorizer" if puts " " puts " Thesis installed.".green puts " Now run `rake db:migrate` to set up your database.".pink else puts " " puts " Thesis uninstalled.".red puts " You will need to remove the database tables manually if you've already run `rake db:migrate`.".pink end end |
#copy_migrations ⇒ Object
21 22 23 24 |
# File 'lib/generators/thesis/install/install_generator.rb', line 21 def copy_migrations migration_template "migrations/thesis_create_page.rb", "db/migrate/thesis_create_page.rb" migration_template "migrations/thesis_create_page_content.rb", "db/migrate/thesis_create_page_content.rb", { skip: true } end |
#create_folders ⇒ Object
26 27 28 29 30 |
# File 'lib/generators/thesis/install/install_generator.rb', line 26 def create_folders copy_file "page_templates/default.html.slim", "app/views/page_templates/default.html.slim" if defined? Slim copy_file "page_templates/default.html.haml", "app/views/page_templates/default.html.haml" if defined? Haml copy_file "page_templates/default.html.erb", "app/views/page_templates/default.html.erb" unless defined? Haml || defined? Slim end |
#install_css ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/thesis/install/install_generator.rb', line 46 def install_css filename = "app/assets/stylesheets/application.css" filename = filename << ".scss" unless File.exists? filename if File.exists? filename existing = File.binread("#{filename}").include?("require thesis") if existing && say_status("skipped", "insert into #{filename}", :yellow) else insert_into_file "#{filename}", after: %r{ *= require_self} do "\n *= require thesis" end end else say_status("skipped", "Couldn't insert into #{filename} -- doesn't exist") end end |
#install_js ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/thesis/install/install_generator.rb', line 32 def install_js filename = "app/assets/javascripts/application.js" existing = File.binread("#{filename}").include?("require thesis") if existing && say_status("skipped", "insert into #{filename}", :yellow) else insert_into_file "#{filename}", after: %r{//= require +['"]?jquery_ujs['"]?} do "\n//= require jquery-ui" + "\n//= require thesis" end end end |
#install_page_is_editable ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/thesis/install/install_generator.rb', line 64 def install_page_is_editable filename = "app/controllers/application_controller.rb" existing = File.binread("#{filename}").include?("def page_is_editable?") if existing && say_status("skipped", "insert into #{filename}", :yellow) else insert_into_file "#{filename}", after: %r{ protect_from_forgery} do "\n" + "\n # Thesis authentication" + "\n def page_is_editable?(page)" + "\n # Add your own criteria here for editing privileges. Examples:" + "\n # current_user.admin? # Basic admin" + "\n # can? :update, page # CanCan" + "\n true # EVERYONE has access right now." + "\n end" end end end |