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, javascripts_scheme = nil) ⇒ 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, 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_result ⇒ Object
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_status ⇒ Object
19 20 21 |
# File 'lib/cup/server/view_scope.rb', line 19 def build_status build_result[:status] end |
#concatenated ⇒ Object
59 60 61 |
# File 'lib/cup/server/view_scope.rb', line 59 def concatenated File.basename Cup.concatenated(:relative => true) end |
#concatenated_size ⇒ Object
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_version ⇒ Object
35 36 37 |
# File 'lib/cup/server/view_scope.rb', line 35 def cup_version Cup::VERSION end |
#file_list ⇒ Object
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 |
#javascripts ⇒ Object
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_count ⇒ Object
87 88 89 |
# File 'lib/cup/server/view_scope.rb', line 87 def lib_count Cup::Directory.current.cupfile.javascripts[:lib].count end |
#minified ⇒ Object
67 68 69 |
# File 'lib/cup/server/view_scope.rb', line 67 def minified File.basename Cup.minified(:relative => true) end |
#minified_percent ⇒ Object
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
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_size ⇒ Object
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 |
#path ⇒ Object
55 56 57 |
# File 'lib/cup/server/view_scope.rb', line 55 def path Cup::Directory.current.path end |
#src_count ⇒ Object
91 92 93 |
# File 'lib/cup/server/view_scope.rb', line 91 def src_count Cup::Directory.current.cupfile.javascripts[:src].count end |
#stylesheets ⇒ Object
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 |
#version ⇒ Object
31 32 33 |
# File 'lib/cup/server/view_scope.rb', line 31 def version Cup.version end |
#visuals ⇒ Object
103 104 105 |
# File 'lib/cup/server/view_scope.rb', line 103 def visuals @server.visuals.values end |