Class: Cup::Server::ViewScope

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

Instance Method Summary collapse

Constructor Details

#initialize(server, javascripts_scheme = nil) ⇒ ViewScope

Returns a new instance of ViewScope.



10
11
12
13
# File 'lib/cup/server/view_scope.rb', line 10

def initialize server, javascripts_scheme=nil
  @server = server
  @javascripts_scheme = javascripts_scheme
end

Instance Method Details

#build_resultObject



23
24
25
26
27
28
29
# File 'lib/cup/server/view_scope.rb', line 23

def build_result
  #return {:status => :failed, :exception => 'you went wrong'}
  @build_result ||= begin
    result = Cup.build
    result[:concatenated][:status] == :ok ? result[:minified] : result[:concatenated]
  end
end

#build_statusObject



19
20
21
# File 'lib/cup/server/view_scope.rb', line 19

def build_status
  build_result[:status]
end

#concatenatedObject



59
60
61
# File 'lib/cup/server/view_scope.rb', line 59

def concatenated
  File.basename Cup.concatenated(:relative => true)
end

#concatenated_sizeObject



63
64
65
# File 'lib/cup/server/view_scope.rb', line 63

def concatenated_size
  "#{File.exist?(Cup.concatenated) ? File.size(Cup.concatenated) : 0} bytes"
end

#cup_versionObject



35
36
37
# File 'lib/cup/server/view_scope.rb', line 35

def cup_version
  Cup::VERSION
end

#file_listObject



95
96
97
98
99
100
101
# File 'lib/cup/server/view_scope.rb', line 95

def file_list
  Dir["#{Cup::Directory.current.path}/**/*"].select do |full_path|
    File.file?(full_path)
  end.map do |full_path|
    File.relative_path(Cup::Directory.current.path, full_path)
  end
end

#javascriptsObject



45
46
47
48
49
50
51
52
53
# File 'lib/cup/server/view_scope.rb', line 45

def javascripts
  @javascripts ||= if @javascripts_scheme.nil?
    []
  else
    Cup::Directory.current.javascripts(@javascripts_scheme).map do |src|
      '/' + File.relative_path(Cup::Directory.current.path, src)
    end
  end
end

#lib_countObject



87
88
89
# File 'lib/cup/server/view_scope.rb', line 87

def lib_count
  Cup::Directory.current.cupfile.javascripts[:lib].count
end

#minifiedObject



67
68
69
# File 'lib/cup/server/view_scope.rb', line 67

def minified
  File.basename Cup.minified(:relative => true)
end

#minified_percentObject



79
80
81
82
83
84
85
# File 'lib/cup/server/view_scope.rb', line 79

def minified_percent

  concatenated_size = File.size(Cup.concatenated).to_f
  minified_size = File.size(Cup.minified).to_f

  (100*(minified_size / concatenated_size)).round(2)
end

#minified_percent_available?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/cup/server/view_scope.rb', line 75

def minified_percent_available?
  File.exists?(Cup.concatenated) and File.size(Cup.concatenated) > 0
end

#minified_sizeObject



71
72
73
# File 'lib/cup/server/view_scope.rb', line 71

def minified_size
  "#{File.exist?(Cup.minified) ? File.size(Cup.minified) : 0} bytes"
end

#nameObject



15
16
17
# File 'lib/cup/server/view_scope.rb', line 15

def name
  Cup.cup_name
end

#pathObject



55
56
57
# File 'lib/cup/server/view_scope.rb', line 55

def path
  Cup::Directory.current.path
end

#src_countObject



91
92
93
# File 'lib/cup/server/view_scope.rb', line 91

def src_count
  Cup::Directory.current.cupfile.javascripts[:src].count
end

#stylesheetsObject



39
40
41
42
43
# File 'lib/cup/server/view_scope.rb', line 39

def stylesheets
  @stylesheets ||= Cup::Directory.current.stylesheets.map do |src|
    '/' + File.relative_path(Cup::Directory.current.path, src)
  end
end

#versionObject



31
32
33
# File 'lib/cup/server/view_scope.rb', line 31

def version
  Cup.version
end

#visualsObject



103
104
105
# File 'lib/cup/server/view_scope.rb', line 103

def visuals
  @server.visuals.values
end