muwu 3.0.0.alpha → 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Muwu
2
2
  class Destination
3
-
4
-
3
+
4
+
5
5
  include Muwu
6
6
 
7
7
 
@@ -14,41 +14,46 @@ module Muwu
14
14
  attr_writer(
15
15
  :output
16
16
  )
17
-
18
-
17
+
18
+
19
19
  MARGIN = ' '
20
-
21
-
20
+
21
+
22
22
  def initialize
23
23
  @margin_depth = 0
24
24
  @output = nil
25
25
  end
26
-
27
-
26
+
27
+
28
28
  def inspect
29
29
  ["#{self.to_s}", "{", inspect_instance_variables, "}"].join(' ')
30
30
  end
31
31
 
32
-
32
+
33
33
  def inspect_instance_variables
34
34
  self.instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ")
35
35
  end
36
-
37
-
38
-
36
+
37
+
38
+
39
39
  public
40
-
41
-
40
+
41
+
42
+ def filename
43
+ @output_filename
44
+ end
45
+
46
+
42
47
  def margin_dec
43
48
  @margin_depth = @margin_depth.to_i - 1
44
49
  end
45
50
 
46
-
51
+
47
52
  def margin_inc
48
53
  @margin_depth = @margin_depth.to_i + 1
49
54
  end
50
55
 
51
-
56
+
52
57
  def margin_indent
53
58
  margin_inc
54
59
  yield
@@ -59,8 +64,8 @@ module Muwu
59
64
  def margin_to_zero
60
65
  @margin_depth = 0
61
66
  end
62
-
63
-
67
+
68
+
64
69
  def output
65
70
  begin
66
71
  if output_is_closed
@@ -70,55 +75,55 @@ module Muwu
70
75
  end
71
76
  end
72
77
  end
73
-
74
-
78
+
79
+
75
80
  def output_is_closed
76
81
  @output == nil
77
82
  end
78
-
79
-
83
+
84
+
80
85
  def output_is_opened
81
86
  @output != nil
82
87
  end
83
-
84
-
88
+
89
+
85
90
  def output_stream
86
91
  announce_open
87
92
  output_open
88
93
  yield
89
94
  output_close
90
95
  end
91
-
92
-
96
+
97
+
93
98
  def padding_vertical(n)
94
99
  output.print ("\n" * n)
95
100
  yield
96
101
  output.print ("\n" * n)
97
- end
98
-
99
-
102
+ end
103
+
104
+
100
105
  def write_inline(value)
101
106
  write_value(value)
102
107
  end
103
108
 
104
-
109
+
105
110
  def write_inline_end(value)
106
111
  write_value(value)
107
112
  write_lf
108
113
  end
109
114
 
110
-
115
+
111
116
  def write_inline_indented(value)
112
117
  write_margin
113
118
  write_value(value)
114
119
  end
115
-
116
-
120
+
121
+
117
122
  def write_lf
118
123
  output.print "\n"
119
124
  end
120
-
121
-
125
+
126
+
122
127
  def write_line(value)
123
128
  write_margin
124
129
  write_value(value)
@@ -129,35 +134,35 @@ module Muwu
129
134
  def write_margin
130
135
  output.print render_current_margin
131
136
  end
132
-
133
-
137
+
138
+
134
139
  def write_value(value)
135
140
  output.print value
136
141
  end
137
-
138
-
142
+
143
+
139
144
 
140
145
  private
141
-
142
-
146
+
147
+
143
148
  def announce_open
144
149
  if @output_class == 'file'
145
150
  puts "- Writing `#{output_filename}`."
146
151
  end
147
152
  end
148
-
153
+
149
154
 
150
155
  def destination_file_open
151
156
  filename = File.join(@output_working_directory, @output_filename)
152
157
  File.new(filename, 'w')
153
158
  end
154
-
155
-
159
+
160
+
156
161
  def destination_stdout
157
162
  $stdout
158
163
  end
159
-
160
-
164
+
165
+
161
166
  def output_close
162
167
  begin
163
168
  if output_is_closed
@@ -168,8 +173,8 @@ module Muwu
168
173
  end
169
174
  margin_to_zero
170
175
  end
171
-
172
-
176
+
177
+
173
178
  def output_close_assignment
174
179
  if File === @output
175
180
  @output.close
@@ -178,8 +183,8 @@ module Muwu
178
183
  @output = nil
179
184
  end
180
185
  end
181
-
182
-
186
+
187
+
183
188
  def output_open
184
189
  margin_to_zero
185
190
  begin
@@ -199,14 +204,13 @@ module Muwu
199
204
  when 'stdout'
200
205
  @output = destination_stdout
201
206
  end
202
- end
203
-
204
-
207
+ end
208
+
209
+
205
210
  def render_current_margin
206
211
  (MARGIN * @margin_depth.to_i)
207
212
  end
208
-
209
-
210
- end
211
- end
212
213
 
214
+
215
+ end
216
+ end
@@ -1,16 +1,16 @@
1
1
  module Muwu
2
2
  class DestinationBuilder
3
-
4
-
3
+
4
+
5
5
  include Muwu
6
-
7
-
6
+
7
+
8
8
  attr_accessor(
9
9
  :destination,
10
10
  :project
11
11
  )
12
-
13
-
12
+
13
+
14
14
  def self.build
15
15
  builder = new
16
16
  yield(builder)
@@ -21,24 +21,24 @@ module Muwu
21
21
  def initialize
22
22
  @destination = Destination.new
23
23
  end
24
-
25
-
24
+
25
+
26
26
  def build_css(project)
27
27
  depends_on_project(project)
28
28
  set_output_class
29
29
  set_output_filename_css
30
30
  set_output_working_directory
31
31
  end
32
-
33
-
32
+
33
+
34
34
  def build_html(project, index)
35
35
  depends_on_project(project)
36
36
  set_output_class
37
37
  set_output_filename_html(index)
38
38
  set_output_working_directory
39
39
  end
40
-
41
-
40
+
41
+
42
42
  def build_js(project)
43
43
  depends_on_project(project)
44
44
  set_output_class
@@ -50,13 +50,13 @@ module Muwu
50
50
  def depends_on_project(project)
51
51
  @project = project
52
52
  end
53
-
54
-
53
+
54
+
55
55
  def set_output_class
56
56
  @destination.output_class = @project.output_destination
57
57
  end
58
-
59
-
58
+
59
+
60
60
  def set_output_filename_css
61
61
  if @destination.output_class == 'file'
62
62
  @destination.output_filename = determine_output_filename_css
@@ -69,26 +69,26 @@ module Muwu
69
69
  @destination.output_filename = determine_output_filename_html(index)
70
70
  end
71
71
  end
72
-
73
-
72
+
73
+
74
74
  def set_output_filename_js
75
75
  if @destination.output_class == 'file'
76
76
  @destination.output_filename = determine_output_filename_js
77
77
  end
78
78
  end
79
-
80
-
79
+
80
+
81
81
  def set_output_working_directory
82
82
  if @destination.output_class == 'file'
83
- @destination.output_working_directory = @project.working_directory
83
+ @destination.output_working_directory = @project.path_compiled
84
84
  end
85
85
  end
86
-
87
-
86
+
87
+
88
88
 
89
89
  private
90
-
91
-
90
+
91
+
92
92
  def determine_output_filename_css
93
93
  filename = ''
94
94
  filename.concat @project.css_basename
@@ -106,22 +106,20 @@ module Muwu
106
106
  filename.concat ".html"
107
107
  filename
108
108
  end
109
-
110
-
109
+
110
+
111
111
  def determine_output_filename_js
112
112
  filename = ''
113
113
  filename.concat @project.js_basename
114
114
  filename.concat ".js"
115
115
  filename
116
116
  end
117
-
118
-
117
+
118
+
119
119
  def index_is_integer_greater_than_zero(index)
120
120
  (Integer === index) && (index >= 1)
121
121
  end
122
-
123
-
122
+
123
+
124
124
  end
125
125
  end
126
-
127
-
@@ -1,10 +1,10 @@
1
1
  module Muwu
2
2
  class Project
3
-
4
-
3
+
4
+
5
5
  include Muwu
6
6
  include Helper
7
-
7
+
8
8
 
9
9
  attr_accessor(
10
10
  :exceptions,
@@ -17,21 +17,21 @@ module Muwu
17
17
  :slug,
18
18
  :working_directory
19
19
  )
20
-
21
-
20
+
21
+
22
22
  def initialize
23
23
  @exceptions = []
24
24
  @instance_date = Time.now.strftime('%Y-%m-%d')
25
25
  @metadata = {}
26
26
  @outline = []
27
27
  end
28
-
29
-
28
+
29
+
30
30
  def inspect
31
31
  ["#{self.to_s}", "{", inspect_instance_variables, "}"].join(' ')
32
32
  end
33
-
34
-
33
+
34
+
35
35
  def inspect_instance_variables
36
36
  self.instance_variables.map { |v| "#{v}=#<#{instance_variable_get(v).class}>" }.join(", ")
37
37
  end
@@ -39,18 +39,18 @@ module Muwu
39
39
 
40
40
 
41
41
  public
42
-
43
-
42
+
43
+
44
44
  def css_manifest_file_does_exist
45
45
  File.exists?(css_manifest_filename) == true
46
46
  end
47
-
48
-
47
+
48
+
49
49
  def css_manifest_filename
50
50
  File.absolute_path(File.join(path_css, 'index.scss'))
51
51
  end
52
-
53
-
52
+
53
+
54
54
  def css_basename
55
55
  if @options.output_file_css_basename.to_s == ''
56
56
  SanitizerHelper::sanitize_destination_file_basename(slug).downcase
@@ -58,40 +58,47 @@ module Muwu
58
58
  SanitizerHelper::sanitize_destination_file_basename(@options.output_file_css_basename).downcase
59
59
  end
60
60
  end
61
-
62
-
61
+
62
+
63
63
  def default_text_block_name
64
64
  Default::PROJECT_OUTLINE[:default_text_block_name]
65
65
  end
66
-
67
-
66
+
67
+
68
+ # def does_not_have_crucial_files
69
+ # exceptions_include?(ProjectException::MetadataFileNotFound) &&
70
+ # exceptions_include?(ProjectException::OptionsFileNotFound) &&
71
+ # exceptions_include?(ProjectException::OutlineFileNotFound)
72
+ # end
73
+
74
+
68
75
  def does_not_have_crucial_files
69
- exceptions_include?(ProjectException::MetadataFileNotFound) &&
70
- exceptions_include?(ProjectException::OptionsFileNotFound) &&
71
- exceptions_include?(ProjectException::OutlineFileNotFound)
76
+ metadata_file_does_not_exist &&
77
+ options_file_does_not_exist &&
78
+ outline_file_does_not_exist
72
79
  end
73
80
 
74
81
 
75
82
  def exceptions_add(exception)
76
83
  @exceptions << exception
77
84
  end
78
-
79
-
85
+
86
+
80
87
  def exceptions_fatal
81
88
  @exceptions.select{ |e| e.type == :fatal }
82
89
  end
83
-
84
-
90
+
91
+
85
92
  def exceptions_include?(exception)
86
93
  @exceptions.map{ |e| e.class }.include?(exception)
87
94
  end
88
-
89
-
95
+
96
+
90
97
  def has_multiple_html_documents
91
98
  @manifest.documents_html_count > 1
92
99
  end
93
-
94
-
100
+
101
+
95
102
  def html_basename
96
103
  if @options.output_file_html_basename.to_s == ''
97
104
  SanitizerHelper::sanitize_destination_file_basename('index').downcase
@@ -99,8 +106,8 @@ module Muwu
99
106
  SanitizerHelper::sanitize_destination_file_basename(@options.output_file_html_basename).downcase
100
107
  end
101
108
  end
102
-
103
-
109
+
110
+
104
111
  def js_basename
105
112
  if @options.output_file_js_basename.to_s == ''
106
113
  SanitizerHelper::sanitize_destination_file_basename(slug).downcase
@@ -108,8 +115,8 @@ module Muwu
108
115
  SanitizerHelper::sanitize_destination_file_basename(@options.output_file_js_basename).downcase
109
116
  end
110
117
  end
111
-
112
-
118
+
119
+
113
120
  def metadata_file_does_exist
114
121
  File.exists?(metadata_filename) == true
115
122
  end
@@ -118,28 +125,28 @@ module Muwu
118
125
  def metadata_file_does_not_exist
119
126
  File.exists?(metadata_filename) == false
120
127
  end
121
-
122
-
128
+
129
+
123
130
  def metadata_filename
124
131
  determine_project_asset_filepath(:metadata)
125
132
  end
126
-
127
-
133
+
134
+
128
135
  def options_file_does_exist
129
136
  File.exists?(options_filename) == true
130
137
  end
131
-
132
-
138
+
139
+
133
140
  def options_file_does_not_exist
134
141
  File.exists?(options_filename) == false
135
142
  end
136
-
137
-
143
+
144
+
138
145
  def options_filename
139
146
  determine_project_asset_filepath(:options)
140
147
  end
141
-
142
-
148
+
149
+
143
150
  def outline_file_does_exist
144
151
  File.exists?(outline_filename) == true
145
152
  end
@@ -148,28 +155,28 @@ module Muwu
148
155
  def outline_file_does_not_exist
149
156
  File.exists?(outline_filename) == false
150
157
  end
151
-
152
-
158
+
159
+
153
160
  def outline_filename
154
161
  determine_project_asset_filepath(:outline)
155
162
  end
156
-
157
-
163
+
164
+
158
165
  def outline_has_more_than_one_document
159
166
  outline_length > 1
160
167
  end
161
-
162
-
168
+
169
+
163
170
  def outline_has_only_one_document
164
171
  outline_length == 1
165
172
  end
166
-
167
-
173
+
174
+
168
175
  def outline_length
169
176
  outline.length
170
177
  end
171
-
172
-
178
+
179
+
173
180
  def outline_text_block_names
174
181
  result = []
175
182
  outline_text_blocks.each do |text_block|
@@ -199,8 +206,8 @@ module Muwu
199
206
  end
200
207
  result
201
208
  end
202
-
203
-
209
+
210
+
204
211
  def outline_text_pathnames
205
212
  @options.outline_text_pathnames
206
213
  end
@@ -209,47 +216,60 @@ module Muwu
209
216
  def outline_text_pathnames_are_explicit
210
217
  @options.outline_text_pathnames == 'explicit'
211
218
  end
212
-
219
+
213
220
 
214
221
  def outline_text_pathnames_are_flexible
215
222
  @options.outline_text_pathnames == 'flexible'
216
223
  end
217
224
 
218
-
225
+
219
226
  def outline_text_pathnames_are_implicit
220
227
  @options.outline_text_pathnames == 'implicit'
221
228
  end
222
-
229
+
223
230
 
224
231
  def outlined_documents
225
232
  @outline
226
233
  end
227
-
228
-
234
+
235
+
229
236
  def outlined_documents_by_index
230
237
  result = {}
231
238
  @outline.each_index do |index|
232
239
  result[index] = @outline[index]
233
- end
240
+ end
234
241
  result
235
242
  end
236
-
237
-
243
+
244
+
238
245
  def output_destination
239
246
  @options.output_destination
240
247
  end
241
-
242
-
248
+
249
+
243
250
  def output_destination_requests_stdout
244
251
  @options.output_destination == 'stdout'
245
252
  end
246
-
247
-
253
+
254
+
248
255
  def output_formats_several
249
256
  @options.output_formats.length > 1
250
257
  end
251
-
252
-
258
+
259
+
260
+
261
+ # TODO: Move path definitions into Muwu::Default::FILEPATHS
262
+
263
+ def path_compiled
264
+ File.absolute_path(File.join(@working_directory, 'compiled'))
265
+ end
266
+
267
+
268
+ def path_compiled_does_exist
269
+ Dir.exists?(path_compiled)
270
+ end
271
+
272
+
253
273
  def path_config
254
274
  File.absolute_path(File.join(@working_directory, 'config'))
255
275
  end
@@ -268,8 +288,8 @@ module Muwu
268
288
  def path_css_colors
269
289
  File.absolute_path(File.join(path_css, 'colors'))
270
290
  end
271
-
272
-
291
+
292
+
273
293
  def path_css_extensions
274
294
  File.absolute_path(File.join(path_css, 'extensions'))
275
295
  end
@@ -278,18 +298,18 @@ module Muwu
278
298
  def path_images
279
299
  File.absolute_path(File.join(@working_directory, 'images'))
280
300
  end
281
-
282
-
301
+
302
+
283
303
  def path_outline
284
304
  @working_directory
285
305
  end
286
-
287
-
306
+
307
+
288
308
  def path_text
289
309
  File.absolute_path(File.join(@working_directory, 'text'))
290
310
  end
291
-
292
-
311
+
312
+
293
313
  def slug
294
314
  if @metadata.has_key?('slug')
295
315
  @metadata['slug']
@@ -297,8 +317,8 @@ module Muwu
297
317
  working_directory_name
298
318
  end
299
319
  end
300
-
301
-
320
+
321
+
302
322
  def sort_outline_text_blocks
303
323
  result = []
304
324
  outline_text_blocks.each do |text_block|
@@ -306,25 +326,25 @@ module Muwu
306
326
  text_block_contents = determine_text_block_contents(text_block)
307
327
  existing_block = result.select { |b| b.has_key?(text_block_name) }.flatten
308
328
  if existing_block.empty?
309
- result << { text_block_name => text_block_contents }
329
+ result << { text_block_name => text_block_contents }
310
330
  else
311
331
  existing_block[text_block_name].concat(text_block_contents)
312
332
  end
313
333
  end
314
334
  result
315
335
  end
316
-
317
-
336
+
337
+
318
338
  def text_block_naming_is_simple
319
339
  outline_text_block_names == [default_text_block_name]
320
340
  end
321
-
341
+
322
342
 
323
343
  def text_block_naming_is_not_simple
324
344
  text_block_naming_is_simple == false
325
345
  end
326
346
 
327
-
347
+
328
348
  def title
329
349
  if @metadata.has_key?('title')
330
350
  @metadata['title']
@@ -332,30 +352,30 @@ module Muwu
332
352
  working_directory_name
333
353
  end
334
354
  end
335
-
336
-
355
+
356
+
337
357
  def will_create_css_file
338
358
  @options.output_formats.include?('css')
339
359
  end
340
-
341
-
360
+
361
+
342
362
  def will_create_html_file_only
343
363
  @options.output_formats == ['html']
344
364
  end
345
-
346
-
365
+
366
+
347
367
  def will_create_javascript_file
348
368
  if will_require_javascript_libraries
349
369
  @options.output_formats.include?('js')
350
370
  end
351
371
  end
352
-
353
-
372
+
373
+
354
374
  def will_require_javascript_libraries
355
375
  @javascript_libraries_requested.count > 0
356
376
  end
357
-
358
-
377
+
378
+
359
379
  def will_embed_at_least_one_asset
360
380
  will_embed_css || will_embed_js
361
381
  end
@@ -364,23 +384,23 @@ module Muwu
364
384
  def will_embed_css
365
385
  will_create_css_file == false
366
386
  end
367
-
368
-
387
+
388
+
369
389
  def will_embed_js
370
390
  will_create_javascript_file == false
371
391
  end
372
-
373
-
392
+
393
+
374
394
  def will_generate_navigators_automatically
375
395
  (outline_has_more_than_one_document) && (@options.generate_navigators_automatically == true) && (@options.output_destination == 'file')
376
396
  end
377
-
378
-
397
+
398
+
379
399
  def will_generate_subcontents_automatically
380
400
  (outline_has_more_than_one_document) && (@options.generate_subcontents_automatically == true)
381
401
  end
382
-
383
-
402
+
403
+
384
404
  def will_render_section_numbers
385
405
  @options.render_section_numbers == true
386
406
  end
@@ -389,32 +409,32 @@ module Muwu
389
409
  def will_not_generate_navigators_automatically
390
410
  not will_generate_navigators_automatically
391
411
  end
392
-
393
-
412
+
413
+
394
414
  def will_not_generate_subcontents_automatically
395
415
  not will_generate_subcontents_automatically
396
416
  end
397
-
398
-
417
+
418
+
399
419
  def working_directory_name
400
420
  @working_directory.split(File::SEPARATOR)[-1]
401
421
  end
402
-
403
-
422
+
423
+
404
424
 
405
425
  private
406
-
407
-
426
+
427
+
408
428
  def determine_project_asset_filepath(type)
409
429
  File.absolute_path(File.join(@working_directory, Default::FILEPATHS[type], Default::FILENAMES[type]))
410
430
  end
411
431
 
412
-
432
+
413
433
  def determine_text_block_contents(text_block)
414
434
  text_block.flatten[1]
415
435
  end
416
-
417
-
436
+
437
+
418
438
  def determine_text_block_name(text_block)
419
439
  directive = text_block.flatten[0]
420
440
  components = directive.partition(RegexpLib.outline_text_plus_whitespace)
@@ -424,7 +444,7 @@ module Muwu
424
444
  end
425
445
  text_block_name
426
446
  end
427
-
428
-
447
+
448
+
429
449
  end
430
- end
450
+ end