Module: MqReporter

Defined in:
lib/mq_reporter.rb,
lib/mq_reporter/cli.rb,
lib/mq_reporter/version.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =

The current gem version of MqReporter

'0.0.2'

Class Method Summary collapse

Class Method Details

.add_stylesheet_to_layout(stylesheet, layout_file, filename) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mq_reporter.rb', line 38

def add_stylesheet_to_layout(stylesheet, layout_file, filename)
  layout_content = File.read(layout_file)
  add_to_layout  = "<% if Rails.env.development? %>\n\t<%= stylesheet_link_tag \"#{filename}\" %>\n<% end %>"
  File.open(layout_file, 'wb') do |f|
    # TODO rather than just appending to the end of the file, put it in the <head>
    #      of the document immediately under the stylesheet_include_tag
    f.puts layout_content
    f.puts ""
    f.puts add_to_layout
  end
end

.download_file(stylesheet) ⇒ Object



32
33
34
35
36
# File 'lib/mq_reporter.rb', line 32

def download_file(stylesheet)
  url = "https://raw.github.com/davidcochran/CSS3-Media-Query-Reporter/master/mediaquery-reporter.css"
  c   = Curl::Easy.perform(url).body_str
  File.open("#{ stylesheet }", 'w') { |f| f.write(c) }
end

.init(filename = "mq_reporter") ⇒ Object

Copies the mq_reporter.css file to vendor/assets/stylesheets and adds it the application layout file.

Parameters:

  • mq_reporter (String)

    the name of the CSS file to add to vendor/assets/stylesheets

See Also:

  • MqReporter::MqReporter.init


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mq_reporter.rb', line 16

def init(filename = "mq_reporter")
  stylesheet  = "#{ Dir.pwd }/vendor/assets/stylesheets/#{ filename }.css"
  # TODO Make it so it doesn't hard code the .erb file. (Allow use of HAML, etc.)
  layout_file = "#{ Dir.pwd }/app/views/layouts/application.html.erb"

  # TODO Turn this into a begin, rescue, end block like Guard uses.
  if !File.exist?(stylesheet)
    # Add mq_reporter.css to vendor/assets/stylesheets if the file isn't already there.
    download_file(stylesheet)
  else
    # TODO Verify the file contents are the same. If they aren't, overwrite the old file with the new one.
  end

  add_stylesheet_to_layout(stylesheet, layout_file, filename)
end