Class: Rugular::Build

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/rugular/tasks/build.rb

Instance Method Summary collapse

Instance Method Details

#check_for_rugular_directoryObject



13
14
15
16
17
18
# File 'lib/rugular/tasks/build.rb', line 13

def check_for_rugular_directory
  ::Rugular::AppChecker.check_for_rugular_directory(
    task_name: self.class.name,
    root_directory: destination_root
  )
end

#compile_bower_javascriptObject



26
27
28
29
30
# File 'lib/rugular/tasks/build.rb', line 26

def compile_bower_javascript
  File.open('dist/vendor.js', 'w') do |file|
    file.write(bower_javascript)
  end
end

#create_application_js_fileObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rugular/tasks/build.rb', line 32

def create_application_js_file
  File.open('dist/application.js', 'w') do |file|
    file.write(
      ::Rugular::JavascriptFiles.ordered_array.map do |javascript_file|
        text = File.read(javascript_file).gsub('templateUrl', 'template')

        CoffeeScript.compile(text)
      end.join
    )
  end
end

#inline_template_url_filesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rugular/tasks/build.rb', line 44

def inline_template_url_files
  (Dir.glob('**/*.haml') - ['src/index.haml']).each do |haml_file|
    haml_html = ::Haml::Engine.new(File.read(haml_file), {}).render

    html = haml_html.tr("\n", '').gsub(/'/, "\'").gsub(/"/, '\"')

    html_filename = haml_file.gsub('src/', '').gsub('haml', 'html')

    IO.write('dist/application.js', File.open('dist/application.js') do |f|
      f.read.gsub(html_filename, html)
    end)
  end
end

#write_dist_index_html_fileObject



20
21
22
23
24
# File 'lib/rugular/tasks/build.rb', line 20

def write_dist_index_html_file
  File.open('dist/index.html', 'w') do |file|
    file.write ::Haml::Engine.new(File.read('src/index.haml')).render
  end
end