Class: ItsSwiss::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ItsSwiss::Generators::InstallGenerator
- Defined in:
- lib/generators/its_swiss/install/install_generator.rb
Overview
Four things, each of them easy to get wrong by hand and quiet when it is wrong. Everything else the library does is a gem dependency and needs no generator at all: Propshaft finds the stylesheets, and the engine pins its own JavaScript so that upgrading the gem is enough to get the new file.
Instance Method Summary collapse
- #create_theme_stylesheet ⇒ Object
-
#mount_the_specimen ⇒ Object
Development only, and the controller refuses it a second time: the specimen names every component the library has, and a route is a line in a file someone can move.
-
#render_through_the_shell ⇒ Object
An application that has already chosen a layout has chosen it.
- #say_what_is_left ⇒ Object
Instance Method Details
#create_theme_stylesheet ⇒ Object
15 16 17 |
# File 'lib/generators/its_swiss/install/install_generator.rb', line 15 def create_theme_stylesheet template "theme.css", "app/assets/stylesheets/theme.css" end |
#mount_the_specimen ⇒ Object
Development only, and the controller refuses it a second time: the specimen names every component the library has, and a route is a line in a file someone can move.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/its_swiss/install/install_generator.rb', line 33 def mount_the_specimen routes = "config/routes.rb" return say_status(:skip, "#{routes} not found", :yellow) unless exists?(routes) return say_status(:skip, "the specimen is already mounted", :yellow) if read(routes).include?("ItsSwiss::Engine") inject_into_file routes, after: /Rails\.application\.routes\.draw do\n/ do <<~RUBY.indent(2) if Rails.env.development? mount ItsSwiss::Engine => "/its-swiss" end RUBY end end |
#render_through_the_shell ⇒ Object
An application that has already chosen a layout has chosen it.
20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/its_swiss/install/install_generator.rb', line 20 def render_through_the_shell controller = "app/controllers/application_controller.rb" return say_status(:skip, "#{controller} not found", :yellow) unless exists?(controller) contents = read(controller) return say_status(:skip, "#{controller} already chooses a layout", :yellow) if contents.match?(/^\s*layout\s/) inject_into_class controller, "ApplicationController", %( layout "its_swiss/shell"\n) end |
#say_what_is_left ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/generators/its_swiss/install/install_generator.rb', line 48 def say_what_is_left say <<~TEXT its-swiss is installed. What is left is yours: app/assets/stylesheets/theme.css the accent, the typeface, the grid /its-swiss/specimen every component, rendered twice The library ships no typeface and no palette. Set --accent to one colour and read the specimen with it unset: if the page still works, the value scale is doing the work. TEXT end |