Class: Bootswatch::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Bootswatch::Generators::InstallGenerator
- Defined in:
- lib/generators/bootswatch/install/install_generator.rb
Constant Summary collapse
- DEFAULT_RAILS_APP_JS_FILE =
'app/assets/javascripts/application.js'
- DEFAULT_RAILS_APP_CSS_FILE =
'app/assets/stylesheets/application.css'
- DEFAULT_THEME_NAME =
'bootswatch'
Instance Method Summary collapse
- #add_assets ⇒ Object
- #add_javascripts ⇒ Object
- #add_stylesheets ⇒ Object
- #remove_require_tree_directives ⇒ Object
- #theme_info ⇒ Object
- #theme_name ⇒ Object
- #use_default_theme_name? ⇒ Boolean
Instance Method Details
#add_assets ⇒ Object
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 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 40 def add_assets if use_default_theme_name? if File.exist?(DEFAULT_RAILS_APP_JS_FILE) unless File.read(DEFAULT_RAILS_APP_JS_FILE).include?(theme_name) insert_into_file DEFAULT_RAILS_APP_JS_FILE, "//= require #{theme_name}/loader\n//= require #{theme_name}/bootswatch\n", :after => "jquery_ujs\n" end else template 'application.js.tt', DEFAULT_RAILS_APP_JS_FILE, {theme_name: theme_name, theme_info: theme_info} end if File.exist?(DEFAULT_RAILS_APP_CSS_FILE) unless File.read(DEFAULT_RAILS_APP_CSS_FILE).include?(theme_name) insert_into_file DEFAULT_RAILS_APP_CSS_FILE, " *= require #{theme_name}/loader\n *= require #{theme_name}/bootswatch\n", :after => "require_self\n" end else template 'application.css.tt', DEFAULT_RAILS_APP_CSS_FILE, {theme_name: theme_name, theme_info: theme_info} end else template 'application.js.tt', "app/assets/javascripts/#{theme_name}.js", {theme_name: theme_name, theme_info: theme_info} template 'application.css.tt', "app/assets/stylesheets/#{theme_name}.css", {theme_name: theme_name, theme_info: theme_info} end end |
#add_javascripts ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 70 def add_javascripts javascripts_dest_path = "app/assets/javascripts/#{theme_name}" empty_directory javascripts_dest_path template 'loader.js.tt', File.join(javascripts_dest_path,'loader.js'), {theme_name: theme_name, theme_info: theme_info} # upgrade to new extension to trigger recompile if File.exist?(File.join(javascripts_dest_path,'bootswatch.js')) File.rename(File.join(javascripts_dest_path,'bootswatch.js'), File.join(javascripts_dest_path,'bootswatch.js')) end template 'bootswatch.js.tt', File.join(javascripts_dest_path,'bootswatch.js'), {theme_name: theme_name, theme_info: theme_info} end |
#add_stylesheets ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 86 def add_stylesheets stylesheets_dest_path = "app/assets/stylesheets/#{theme_name}" empty_directory stylesheets_dest_path bootstrap_less_imports = File.read(find_in_source_paths('bootstrap.less')).scan(Less::Rails::ImportProcessor::IMPORT_SCANNER).flatten.compact.uniq template 'loader.css.less.tt', File.join(stylesheets_dest_path,'loader.css.less'), {less_imports: bootstrap_less_imports, theme_name: theme_name, theme_info: theme_info} # now variables and mixins template 'variables.less.tt', File.join(stylesheets_dest_path,'variables.less'), {theme_name: theme_name, theme_info: theme_info} template 'mixins.less.tt', File.join(stylesheets_dest_path,'mixins.less'), {theme_name: theme_name, theme_info: theme_info} # upgrade to new extension to trigger recompile if File.exist?(File.join(stylesheets_dest_path,'bootswatch.less')) File.rename(File.join(stylesheets_dest_path,'bootswatch.less'), File.join(stylesheets_dest_path,'bootswatch.css.less')) end template 'bootswatch.css.less.tt', File.join(stylesheets_dest_path,'bootswatch.css.less'), {theme_name: theme_name, theme_info: theme_info} template 'base.less.tt', File.join(stylesheets_dest_path,'base.less'), {theme_name: theme_name, theme_info: theme_info} end |
#remove_require_tree_directives ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 30 def remove_require_tree_directives if File.exist?(DEFAULT_RAILS_APP_JS_FILE) gsub_file DEFAULT_RAILS_APP_JS_FILE, /\/\/=\s*require_tree\s*\./, '' end if File.exist?(DEFAULT_RAILS_APP_CSS_FILE) gsub_file DEFAULT_RAILS_APP_CSS_FILE, /=\s*require_tree\s*\./, '' end end |
#theme_info ⇒ Object
26 27 28 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 26 def theme_info "#{use_default_theme_name? ? 'bootstrap'.capitalize : theme_name.capitalize}" end |
#theme_name ⇒ Object
18 19 20 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 18 def theme_name file_name end |
#use_default_theme_name? ⇒ Boolean
22 23 24 |
# File 'lib/generators/bootswatch/install/install_generator.rb', line 22 def use_default_theme_name? theme_name === DEFAULT_THEME_NAME end |