Class: Rugular::Abstract

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

Instance Method Summary collapse

Instance Method Details

#bower_jsonObject



29
30
31
# File 'lib/rugular/tasks/abstract.rb', line 29

def bower_json
  @_json ||= JSON.parse(File.read('bower.json')).to_h
end

#check_for_rugular_directoryObject



22
23
24
25
26
27
# File 'lib/rugular/tasks/abstract.rb', line 22

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

#increment_bower_version_if_file_existsObject



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

def increment_bower_version_if_file_exists
  return unless File.exists? "release/#{app_name}.js"

  new_bower_json = bower_json.tap do |json|
    json['version'] = next_version
  end

  File.open('bower.json', 'w') do |file|
    file.write new_bower_json
  end
end

#inline_template_url_filesObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rugular/tasks/abstract.rb', line 55

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(release_js, File.open(release_js) do |f|
      f.read.gsub(html_filename, html)
    end)

    IO.write(release_min_js, File.open(release_js) do |f|
      f.read.gsub(html_filename, html)
    end)
  end
end

#write_application_css_fileObject



73
74
75
# File 'lib/rugular/tasks/abstract.rb', line 73

def write_application_css_file
  `sass .application.sass release/#{app_name}.css -r sass-globbing`
end

#write_release_js_filesObject



45
46
47
48
49
50
51
52
53
# File 'lib/rugular/tasks/abstract.rb', line 45

def write_release_js_files
  File.open(release_js, 'w') do |file|
    file.write(one_coffeescript_file)
  end

  File.open(release_min_js, 'w') do |file|
    file.write(Uglifier.compile(one_coffeescript_file))
  end
end