class CubaGenie::ViewsSetup
Public Class Methods
new(**args)
click to toggle source
Calls superclass method
CubaGenie::Command::new
# File lib/cuba_genie/views_setup.rb, line 18 def initialize(**args) @project_name = args[:project_name] #TODO: allow for choice of different template engines @description = 'Setting up views' @rollback_msg = "rolling back Views" @bootstrap_version = args[:bootstrap_version] || 'n' super end
Public Instance Methods
execute()
click to toggle source
Calls superclass method
CubaGenie::Command#execute
# File lib/cuba_genie/views_setup.rb, line 27 def execute super do layout_view_formatters = [nil, @project_name.capitalize, nil] if ALLOWED_BOOTSTRAP_VERSIONS.include? @bootstrap_version bootstrap_location = "https://github.com/twbs/bootstrap/releases/download/v#{@bootstrap_version}/bootstrap-#{@bootstrap_version}-dist.zip" download_bootstrap_from bootstrap_location extract_bootstrap_to 'public' layout_view_formatters = [BOOTSTRAP_CSS, @project_name.capitalize, BOOTSTRAP_JS] end create_view_files(layout_view_formatters) end end
Private Instance Methods
create_view_files(layout_view_formatters)
click to toggle source
# File lib/cuba_genie/views_setup.rb, line 44 def create_view_files(layout_view_formatters) FileUtils.mkdir "views" @dirs_created << "views" home_file, layout_file = 'views/home.mote', 'views/layout.mote' File.open(home_file, 'w') {|f| f.write(HOME_VIEW_CONTENT % @project_name) } File.open(layout_file, 'w') {|f| f.write(LAYOUT_VIEW_CONTENT % layout_view_formatters) } @files_created << "#{Dir.pwd}/#{home_file}" << "#{Dir.pwd}/#{layout_file}" end
download_bootstrap_from(location)
click to toggle source
# File lib/cuba_genie/views_setup.rb, line 55 def download_bootstrap_from(location) FileUtils.mkdir "temp" target = 'temp/bootstrap.zip' open(target, 'wb') do |file| file << open(location).read end # add the jumbotron css to zip file Zip::File.open(target, Zip::File::CREATE) do |zipfile| zipfile.get_output_stream("css/jumbotron.css") do |f| f.puts %Q( body { padding-top: 50px; padding-bottom: 20px; } ) end end target end
extract_bootstrap_to(directory)
click to toggle source
# File lib/cuba_genie/views_setup.rb, line 78 def extract_bootstrap_to(directory) FileUtils.mkdir directory Zip::File.open('temp/bootstrap.zip') do |zip_file| zip_file.each do |entry| puts "...extracting #{entry.name}" new_name = entry.name.gsub("bootstrap-#{@bootstrap_version}-dist", "") entry.extract("#{directory}/#{new_name}") end end @dirs_created << directory FileUtils.rm_rf('temp') end