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, build_result, javascripts_scheme) ⇒ ViewScope

Returns a new instance of ViewScope.



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

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

Instance Method Details

#build_resultObject



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

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

#build_statusObject



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

def build_status
  build_result[:status]
end

#concatenatedObject



57
58
59
# File 'lib/cup/server/view_scope.rb', line 57

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

#concatenated_sizeObject



61
62
63
# File 'lib/cup/server/view_scope.rb', line 61

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

#cup_versionObject



33
34
35
# File 'lib/cup/server/view_scope.rb', line 33

def cup_version
  Cup::VERSION
end

#file_listObject



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

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



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

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



85
86
87
# File 'lib/cup/server/view_scope.rb', line 85

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

#minifiedObject



65
66
67
# File 'lib/cup/server/view_scope.rb', line 65

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

#minified_percentObject



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

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)


73
74
75
# File 'lib/cup/server/view_scope.rb', line 73

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

#minified_sizeObject



69
70
71
# File 'lib/cup/server/view_scope.rb', line 69

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

#nameObject



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

def name
  Cup.cup_name
end

#pathObject



53
54
55
# File 'lib/cup/server/view_scope.rb', line 53

def path
  Cup::Directory.current.path
end

#src_countObject



89
90
91
# File 'lib/cup/server/view_scope.rb', line 89

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

#stylesheetsObject



37
38
39
40
41
# File 'lib/cup/server/view_scope.rb', line 37

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

#versionObject



29
30
31
# File 'lib/cup/server/view_scope.rb', line 29

def version
  Cup.version
end

#visualsObject



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

def visuals
  @server.visuals.values
end