cup 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cup/builder.rb CHANGED
@@ -9,15 +9,27 @@ module Cup
9
9
 
10
10
  def initialize directory
11
11
  @directory = directory
12
- @before_build_enabled = true
13
- @after_build_enabled = true
12
+
13
+ @build_directory = @directory.path + 'build'
14
+
15
+ if File.exists? @build_directory
16
+ if File.file? @build_directory
17
+ raise "Cannot build, build directory is a file"
18
+ end
19
+ else
20
+ Dir.mkdir @build_directory
21
+ end
14
22
  end
15
23
 
16
24
  def build *params
25
+
17
26
  cupfile.before_build.call
27
+
18
28
  concatenated = concatenate *params
19
29
  minified = minify *params
30
+
20
31
  cupfile.after_build.call
32
+
21
33
  {
22
34
  :concatenated => concatenated,
23
35
  :minified => minified
@@ -71,7 +83,7 @@ module Cup
71
83
  options = default_options.merge options
72
84
  cli = options[:cli]
73
85
 
74
- build_directory = "#{directory.path.to_s}/build"
86
+ build_directory = @build_directory.to_s
75
87
  mkdir build_directory unless Dir.exists?(build_directory)
76
88
  file = File.open(output_file, 'w')
77
89
 
@@ -3,13 +3,12 @@ ENV['RACK_ENV'] ||= File.exists?(File.expand_path('../../../development', __FILE
3
3
  require 'thor'
4
4
  require 'pathname'
5
5
  require 'cup'
6
- require 'cup/builder'
7
- require 'cup/directory'
8
- require 'cup/server/app'
9
6
 
10
7
  module Cup
8
+ autoload :Server, 'cup/server/app'
9
+
11
10
  class CommandLine < Thor
12
-
11
+
13
12
  include Thor::Actions
14
13
 
15
14
  class Helper
data/lib/cup/directory.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  require 'pathname'
2
- require 'rake'
3
- require 'cup/cupfile'
4
2
 
5
3
  module Cup
6
-
4
+ autoload :Cupfile, 'cup/cupfile'
5
+ autoload :FileList, 'rake'
7
6
  # Represents the directory that holds a cup
8
7
  class Directory
9
8
 
@@ -36,12 +36,17 @@ module Cup
36
36
  set :views, gem_root_path('views')
37
37
  set :public_folder, false #Cup::Directory.current.path.to_s
38
38
 
39
+ def build
40
+ @build_result = Cup.build
41
+ end
42
+
39
43
  def view_scope(javascripts_scheme=:debug)
40
- @view_scope = ViewScope.new self, javascripts_scheme
44
+ @view_scope = ViewScope.new self, @build_result, javascripts_scheme
41
45
  end
42
46
 
43
47
  def view (template, options={})
44
-
48
+ build
49
+
45
50
  options = {
46
51
  :scope => view_scope(options.delete(:javascripts_scheme) || :debug),
47
52
  :layout => true
@@ -59,10 +64,12 @@ module Cup
59
64
  end
60
65
 
61
66
  get '/cup.sass' do
67
+ content_type 'text/css'
62
68
  sass File.read(gem_root_path('views/cup.sass'))
63
69
  end
64
70
 
65
71
  get '/cup.coffee' do
72
+ content_type 'application/javascript'
66
73
  coffee File.read(gem_root_path('views/cup.coffee'))
67
74
  end
68
75
 
@@ -74,7 +81,7 @@ module Cup
74
81
 
75
82
  content_type 'text/javascript'
76
83
 
77
- result = Cup.build[:concatenated]
84
+ result = build[:concatenated]
78
85
  if result[:status] == :ok
79
86
  body result[:output]
80
87
  else
@@ -86,7 +93,7 @@ module Cup
86
93
 
87
94
  content_type 'text/javascript'
88
95
 
89
- result = Cup.build[:minified]
96
+ result = build[:minified]
90
97
  if result[:status] == :ok
91
98
  body result[:output]
92
99
  else
@@ -130,8 +137,11 @@ module Cup
130
137
  end
131
138
 
132
139
  get '**/*.sass' do
140
+
133
141
  file = File.relative_path(Cup::Directory.current.path, request.path[1..-1])
134
142
  return pass unless File.file? file
143
+
144
+ content_type 'text/css'
135
145
  sass File.read(file)
136
146
  end
137
147
 
@@ -7,8 +7,9 @@ module Cup
7
7
  module Server
8
8
  class ViewScope
9
9
 
10
- def initialize server, javascripts_scheme=nil
10
+ def initialize server, build_result, javascripts_scheme
11
11
  @server = server
12
+ @build_result = build_result
12
13
  @javascripts_scheme = javascripts_scheme
13
14
  end
14
15
 
@@ -22,10 +23,7 @@ module Cup
22
23
 
23
24
  def build_result
24
25
  #return {:status => :failed, :exception => 'you went wrong'}
25
- @build_result ||= begin
26
- result = Cup.build
27
- result[:concatenated][:status] == :ok ? result[:minified] : result[:concatenated]
28
- end
26
+ @build_result[:concatenated][:status] == :ok ? @build_result[:minified] : @build_result[:concatenated]
29
27
  end
30
28
 
31
29
  def version
@@ -59,7 +57,7 @@ module Cup
59
57
  def concatenated
60
58
  File.basename Cup.concatenated(:relative => true)
61
59
  end
62
-
60
+
63
61
  def concatenated_size
64
62
  "#{File.exist?(Cup.concatenated) ? File.size(Cup.concatenated) : 0} bytes"
65
63
  end
@@ -67,7 +65,7 @@ module Cup
67
65
  def minified
68
66
  File.basename Cup.minified(:relative => true)
69
67
  end
70
-
68
+
71
69
  def minified_size
72
70
  "#{File.exist?(Cup.minified) ? File.size(Cup.minified) : 0} bytes"
73
71
  end
data/lib/cup/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cup
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/cup.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'cup/version'
2
- require 'cup/directory'
3
- require 'cup/cupfile'
4
- require 'cup/builder'
5
2
 
6
3
  module Cup
4
+ autoload :Directory, 'cup/directory'
5
+ autoload :Builder, 'cup/builder'
6
+
7
7
  class << self
8
8
 
9
9
  def version *params
@@ -23,27 +23,27 @@ module Cup
23
23
  end
24
24
 
25
25
  def build! *params
26
- Cup::Builder.new(directory).build! *params
26
+ Builder.new(directory).build! *params
27
27
  end
28
28
 
29
29
  def build *params
30
- Cup::Builder.new(directory).build *params
30
+ Builder.new(directory).build *params
31
31
  end
32
32
 
33
33
  def concatenate! *params
34
- Cup::Builder.new(directory).concatenate! *params
34
+ Builder.new(directory).concatenate! *params
35
35
  end
36
36
 
37
37
  def concatenate *params
38
- Cup::Builder.new(directory).concatenate *params
38
+ Builder.new(directory).concatenate *params
39
39
  end
40
40
 
41
41
  def minify! *params
42
- Cup::Builder.new(directory).minify! *params
42
+ Builder.new(directory).minify! *params
43
43
  end
44
44
 
45
45
  def minify *params
46
- Cup::Builder.new(directory).minify *params
46
+ Builder.new(directory).minify *params
47
47
  end
48
48
 
49
49
  def define &block
@@ -51,7 +51,7 @@ module Cup
51
51
  end
52
52
  private
53
53
  def directory
54
- @directory ||= Cup::Directory.current
54
+ @directory ||= Directory.current
55
55
  end
56
56
  end
57
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000Z
12
+ date: 2011-10-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &2152089920 !ruby/object:Gem::Requirement
16
+ requirement: &2151939960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152089920
24
+ version_requirements: *2151939960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2152056960 !ruby/object:Gem::Requirement
27
+ requirement: &2151938000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152056960
35
+ version_requirements: *2151938000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: therubyracer
38
- requirement: &2152051520 !ruby/object:Gem::Requirement
38
+ requirement: &2151932160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152051520
46
+ version_requirements: *2151932160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: uglifier
49
- requirement: &2151940820 !ruby/object:Gem::Requirement
49
+ requirement: &2151929340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2151940820
57
+ version_requirements: *2151929340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sinatra
60
- requirement: &2151931940 !ruby/object:Gem::Requirement
60
+ requirement: &2151925780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2151931940
68
+ version_requirements: *2151925780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: slim
71
- requirement: &2151912880 !ruby/object:Gem::Requirement
71
+ requirement: &2151922360 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2151912880
79
+ version_requirements: *2151922360
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sass
82
- requirement: &2151895180 !ruby/object:Gem::Requirement
82
+ requirement: &2151906040 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2151895180
90
+ version_requirements: *2151906040
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: coffee-script
93
- requirement: &2151883300 !ruby/object:Gem::Requirement
93
+ requirement: &2151885320 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2151883300
101
+ version_requirements: *2151885320
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: yard
104
- requirement: &2151880700 !ruby/object:Gem::Requirement
104
+ requirement: &2151879660 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2151880700
112
+ version_requirements: *2151879660
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rack
115
- requirement: &2151875000 !ruby/object:Gem::Requirement
115
+ requirement: &2151864360 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - =
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.3.3
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2151875000
123
+ version_requirements: *2151864360
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: ruby-debug19
126
- requirement: &2151872260 !ruby/object:Gem::Requirement
126
+ requirement: &2151859040 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2151872260
134
+ version_requirements: *2151859040
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rspec
137
- requirement: &2151870340 !ruby/object:Gem::Requirement
137
+ requirement: &2151856060 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2151870340
145
+ version_requirements: *2151856060
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: shoulda
148
- requirement: &2151867340 !ruby/object:Gem::Requirement
148
+ requirement: &2151853820 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2151867340
156
+ version_requirements: *2151853820
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: statemachine
159
- requirement: &2151864300 !ruby/object:Gem::Requirement
159
+ requirement: &2151850200 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2151864300
167
+ version_requirements: *2151850200
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: rack-test
170
- requirement: &2151852720 !ruby/object:Gem::Requirement
170
+ requirement: &2151846300 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2151852720
178
+ version_requirements: *2151846300
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: thin
181
- requirement: &2151846160 !ruby/object:Gem::Requirement
181
+ requirement: &2151841700 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ! '>='
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: '0'
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *2151846160
189
+ version_requirements: *2151841700
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: sinatra-reloader
192
- requirement: &2151840500 !ruby/object:Gem::Requirement
192
+ requirement: &2151836120 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ! '>='
@@ -197,7 +197,7 @@ dependencies:
197
197
  version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *2151840500
200
+ version_requirements: *2151836120
201
201
  description:
202
202
  email:
203
203
  - sjltaylor@gmail.com