Module: Layout::Material

Defined in:
lib/myrails/modules/material.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/myrails/modules/material.rb', line 3

def self.included(thor)
  thor.class_eval do
    desc 'generate_material_files', 'Generate material layout files'
    def generate_material_files
      Dir[File.join("#{__dir__}", "..", "templates", "rails", "app", "views", "layout", "material", "**", "*")].each do |file|
        copy_file file, "app/views/layouts/#{File.basename(file)}"
      end
    end
    
    desc 'add_material_gem', 'Add materialize sass and icons gem to Gemfile and run bundler'
    def add_material_gem

      insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
gem 'materialize-sass'
gem 'material_icons'
CODE
      end

      run 'bundle install'
    end
    
    desc 'setup_application_sass', 'add materialize to sass manifest'
    def setup_materialize_css
      insert_into_file 'app/assets/stylesheets/application.css.sass', before: '@import trix' do <<-CODE
@import "materialize/components/color"
$primary-color: color("grey", "darken-3") !default
$secondary-color: color("grey", "base") !default
@import materialize
@import material_icons
CODE
      end
    end
    
    desc 'add_materialize_js', 'add materialize to js manifest'
    def setup_materialize_js
      insert_into_file 'app/assets/javascripts/application.js', before: "//= require trix" do <<-CODE
//= require materialize
  CODE
      end
    end
    desc 'install_material', 'Generate Material css theme'
    def setup_material
      generate_material_files
      setup_materialize_css
      setup_materialize_js
    end

  end
end