Class: Cup::CommandLine::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/cup/command_line.rb

Constant Summary collapse

JasmineStandaloneDistributionURL =
'http://pivotal.github.com/jasmine/downloads/jasmine-standalone-1.1.0.zip'
JQueryURL =
'http://code.jquery.com/jquery.min.js'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Helper

Returns a new instance of Helper.



22
23
24
# File 'lib/cup/command_line.rb', line 22

def initialize (path)
  @root = Pathname.new(path).expand_path
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



20
21
22
# File 'lib/cup/command_line.rb', line 20

def root
  @root
end

Instance Method Details

#cupfileObject



26
27
28
# File 'lib/cup/command_line.rb', line 26

def cupfile
  root + 'Cupfile'
end

#cupfile?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cup/command_line.rb', line 64

def cupfile?
  File.exists?(root + 'Cupfile')
end

#cupfile_default_content(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cup/command_line.rb', line 30

def cupfile_default_content(name)
  <<-CUPFILE
# This file describes the javascript project
# see: https://github.com/sjltaylor/cup
Cup.define do |cup|

  name '#{name}'
  version '0.0.1'
  licence 'licence.txt'

  javascripts do
    vendor 'jasmine.js', :*
  end

end
CUPFILE
end

#download_jasmineObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cup/command_line.rb', line 105

def download_jasmine

  %x{
    set -o errexit # exit if it hits the fan
    set -o nounset # using unset variables is an error

    cd #{root + 'vendor'}

    curl --silent #{JasmineStandaloneDistributionURL} > jasmine.zip
    unzip jasmine.zip -d jasmine

    cd jasmine

    cp `find . | grep -E '.*\.(css|js)'` ..

    cd ..

    rm -rf jasmine
    rm jasmine.zip
  }

  $?.exitstatus == 0
end

#extra_matchers_fileObject



56
57
58
# File 'lib/cup/command_line.rb', line 56

def extra_matchers_file
  root + 'vendor' + 'extra_matchers.js'
end

#get_extra_matchersObject



101
102
103
# File 'lib/cup/command_line.rb', line 101

def get_extra_matchers
  File.read(File.expand_path('../../../js/extra_matchers.js', __FILE__))
end

#get_jqueryObject



72
73
74
75
# File 'lib/cup/command_line.rb', line 72

def get_jquery
  jquery = `curl --silent #{JQueryURL}`
  return jquery if $?.exitstatus == 0
end

#get_licenceObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cup/command_line.rb', line 77

def get_licence
  <<-LICENSE
  Copyright (C) #{Time.now.year} by #{ENV['USER'] || 'THE_MAN'}

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicence, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
LICENSE
end

#jquery_fileObject



52
53
54
# File 'lib/cup/command_line.rb', line 52

def jquery_file
  root + 'vendor' + 'jquery.min.js'
end

#licence_fileObject



68
69
70
# File 'lib/cup/command_line.rb', line 68

def licence_file
  root + 'licence.txt'
end

#rackup_fileObject



60
61
62
# File 'lib/cup/command_line.rb', line 60

def rackup_file
  root + 'config.ru'
end

#standard_directoriesObject



48
49
50
# File 'lib/cup/command_line.rb', line 48

def standard_directories
  %w|src lib vendor spec spec/visual|.map {|dir| root + dir}
end