Class: Flashee::Builders
- Inherits:
-
Object
- Object
- Flashee::Builders
- Defined in:
- lib/flashee/builders.rb
Class Method Summary collapse
-
.file_builder(file_path, file_contents) ⇒ Object
Called by install generators to create a file inside of the apps file structure.
-
.helper_builder(flashee_helper_mode) ⇒ Object
Called by install generators to build the appropriate helper file.
-
.view_builder(flashee_helper_mode) ⇒ Object
Called by install generators to build the appropriate view partial.
Class Method Details
.file_builder(file_path, file_contents) ⇒ Object
Called by install generators to create a file inside of the apps file structure
Parameters:
- file_path
-
Path to file including filename and extension
- file_contents
-
Contents to print into the file_path
Returns:
A file inside file_path containing file_contents
57 58 59 60 61 |
# File 'lib/flashee/builders.rb', line 57 def self.file_builder file_path, file_contents @out_file = File.new(file_path, 'w') @out_file.puts(file_contents) @out_file.close end |
.helper_builder(flashee_helper_mode) ⇒ Object
Called by install generators to build the appropriate helper file
Parameters:
- flashee_helper_mode
-
A string to define what mode to render the templates in
Returns:
A string of the template contents
13 14 15 16 17 |
# File 'lib/flashee/builders.rb', line 13 def self.helper_builder flashee_helper_mode @mode = flashee_helper_mode @template = File.read(File.join(Gem.loaded_specs["flashee"].full_gem_path, "lib", "templates", "flashee_helper.rb.erb")) return ERB.new(@template).result(binding) end |
.view_builder(flashee_helper_mode) ⇒ Object
Called by install generators to build the appropriate view partial
Parameters:
- flashee_helper_mode
-
if flashee_helper_mode is set to “foundation” it will copy the foundation template. Otherwise it will copy the standard template that fits everything else.
Returns:
A string of the template contents
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/flashee/builders.rb', line 30 def self.view_builder flashee_helper_mode @mode = flashee_helper_mode if @mode == "foundation" view_partial_source = File.join(Gem.loaded_specs["flashee"].full_gem_path, "lib", "templates", "_flash_messages_foundation.html.erb") view_partial_target = File.join(Rails.root, "app", "views", "partials", "_flash_messages.html.erb") FileUtils::mkdir_p File.join(Rails.root, "app", "views", "partials") FileUtils.cp_r view_partial_source, view_partial_target else view_partial_source = File.join(Gem.loaded_specs["flashee"].full_gem_path, "lib", "templates", "_flash_messages.html.erb") view_partial_target = File.join(Rails.root, "app", "views", "partials", "_flash_messages.html.erb") FileUtils::mkdir_p File.join(Rails.root, "app", "views", "partials") FileUtils.cp_r view_partial_source, view_partial_target end end |