Class: Cup::Server::ViewScope
- Inherits:
-
Object
- Object
- Cup::Server::ViewScope
- Defined in:
- lib/cup/server/view_scope.rb
Instance Method Summary collapse
- #build_result ⇒ Object
- #build_status ⇒ Object
- #concatenated ⇒ Object
- #concatenated_size ⇒ Object
- #cup_version ⇒ Object
- #file_list ⇒ Object
-
#initialize(server, build_result, javascripts_scheme) ⇒ ViewScope
constructor
A new instance of ViewScope.
- #javascripts ⇒ Object
- #lib_count ⇒ Object
- #minified ⇒ Object
- #minified_percent ⇒ Object
- #minified_percent_available? ⇒ Boolean
- #minified_size ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #src_count ⇒ Object
- #stylesheets ⇒ Object
- #version ⇒ Object
- #visuals ⇒ Object
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_result ⇒ Object
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_status ⇒ Object
20 21 22 |
# File 'lib/cup/server/view_scope.rb', line 20 def build_status build_result[:status] end |
#concatenated ⇒ Object
57 58 59 |
# File 'lib/cup/server/view_scope.rb', line 57 def concatenated File.basename Cup.concatenated(:relative => true) end |
#concatenated_size ⇒ Object
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_version ⇒ Object
33 34 35 |
# File 'lib/cup/server/view_scope.rb', line 33 def cup_version Cup::VERSION end |
#file_list ⇒ Object
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 |
#javascripts ⇒ Object
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_count ⇒ Object
85 86 87 |
# File 'lib/cup/server/view_scope.rb', line 85 def lib_count Cup::Directory.current.cupfile.javascripts[:lib].count end |
#minified ⇒ Object
65 66 67 |
# File 'lib/cup/server/view_scope.rb', line 65 def minified File.basename Cup.minified(:relative => true) end |
#minified_percent ⇒ Object
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
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_size ⇒ Object
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 |
#path ⇒ Object
53 54 55 |
# File 'lib/cup/server/view_scope.rb', line 53 def path Cup::Directory.current.path end |
#src_count ⇒ Object
89 90 91 |
# File 'lib/cup/server/view_scope.rb', line 89 def src_count Cup::Directory.current.cupfile.javascripts[:src].count end |
#stylesheets ⇒ Object
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 |
#version ⇒ Object
29 30 31 |
# File 'lib/cup/server/view_scope.rb', line 29 def version Cup.version end |
#visuals ⇒ Object
101 102 103 |
# File 'lib/cup/server/view_scope.rb', line 101 def visuals @server.visuals.values end |