Class: ReactOnRails::Generators::BootstrapGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ReactOnRails::Generators::BootstrapGenerator
show all
- Includes:
- GeneratorHelper
- Defined in:
- lib/generators/react_on_rails/bootstrap_generator.rb
Instance Method Summary
collapse
#copy_file_and_missing_parent_directories, #dest_dir_exists?, #dest_file_exists?, #empty_directory_with_keep_file, #keep_file, #setup_file_error, #symlink_dest_file_to_dest_file
Instance Method Details
#add_bootstrap_sprockets_to_application_js ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 68
def add_bootstrap_sprockets_to_application_js
data = <<-DATA.strip_heredoc
// bootstrap-sprockets depends on generated/vendor-bundle for jQuery.
//= require bootstrap-sprockets
DATA
app_js_path = "app/assets/javascripts/application.js"
found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
if found_app_js
append_to_file(found_app_js, data)
else
create_file(app_js_path, data)
end
end
|
#add_bootstrap_sprockets_to_gemfile ⇒ Object
64
65
66
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 64
def add_bootstrap_sprockets_to_gemfile
append_to_file("Gemfile", "gem 'bootstrap-sass'\n")
end
|
#copy_bootstrap_files ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 12
def copy_bootstrap_files
base_path = "bootstrap/"
%w(app/assets/stylesheets/_bootstrap-custom.scss
client/assets/stylesheets/_post-bootstrap.scss
client/assets/stylesheets/_pre-bootstrap.scss
client/assets/stylesheets/_react-on-rails-sass-helper.scss
client/bootstrap-sass.config.js).each { |file| copy_file(base_path + file, file) }
end
|
#create_application_scss_if_necessary ⇒ Object
if there still is not application.scss, just create one
22
23
24
25
26
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 22
def create_application_scss_if_necessary
path = File.join(destination_root, "app/assets/stylesheets/application.scss")
return if File.exist?(path)
File.open(path, "w") { |f| f.puts "// Created by React on Rails gem\n\n" }
end
|
#prepend_to_application_scss ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 28
def prepend_to_application_scss
data = <<-DATA.strip_heredoc
// DO NOT REQUIRE TREE! It will interfere with load order!
// Account for differences between Rails and Webpack Sass code.
$rails: true;
// Included from bootstrap-sprockets gem and loaded in app/assets/javascripts/application.rb
@import 'bootstrap-sprockets';
// Customizations - needs to be imported after bootstrap-sprocket but before bootstrap-custom!
// The _pre-bootstrap.scss file is located under
// client/assets/stylesheets, which has been added to the Rails asset
// pipeline search path. See config/application.rb.
@import 'pre-bootstrap';
// These scss files are located under client/assets/stylesheets
// (which has been added to the Rails asset pipeline search path in config/application.rb).
@import 'bootstrap-custom';
// This must come after all the boostrap styles are loaded so that these styles can override those.
@import 'post-bootstrap';
DATA
application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
append_to_file(application_scss, data)
end
|
#strip_application_scss_of_incompatible_sprockets_statements ⇒ Object
58
59
60
61
62
|
# File 'lib/generators/react_on_rails/bootstrap_generator.rb', line 58
def strip_application_scss_of_incompatible_sprockets_statements
application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
gsub_file(application_scss, "*= require_tree .", "")
gsub_file(application_scss, "*= require_self", "")
end
|