muwu 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/muwu +5 -0
- data/lib/muwu.rb +38 -0
- data/lib/muwu/cli/cli.rb +143 -0
- data/lib/muwu/cli/cli_help.rb +28 -0
- data/lib/muwu/cli/help/compile +22 -0
- data/lib/muwu/cli/help/concat +8 -0
- data/lib/muwu/cli/help/heading +2 -0
- data/lib/muwu/cli/help/inspect +7 -0
- data/lib/muwu/cli/help/new +8 -0
- data/lib/muwu/cli/help/reset +14 -0
- data/lib/muwu/cli/help/summary +14 -0
- data/lib/muwu/controller/controller.rb +120 -0
- data/lib/muwu/controller/controller_interaction.rb +146 -0
- data/lib/muwu/default/default.rb +51 -0
- data/lib/muwu/destination/destination.rb +212 -0
- data/lib/muwu/destination_builder/destination_builder.rb +127 -0
- data/lib/muwu/helper/hash_helper.rb +37 -0
- data/lib/muwu/helper/html_href_helper.rb +101 -0
- data/lib/muwu/helper/outline_helper.rb +160 -0
- data/lib/muwu/helper/regexp_lib.rb +101 -0
- data/lib/muwu/helper/sanitizer_helper.rb +50 -0
- data/lib/muwu/manifest/manifest.rb +158 -0
- data/lib/muwu/manifest_builder/manifest_builder.rb +102 -0
- data/lib/muwu/manifest_task/contents.rb +42 -0
- data/lib/muwu/manifest_task/document_css.rb +25 -0
- data/lib/muwu/manifest_task/document_html.rb +69 -0
- data/lib/muwu/manifest_task/document_js.rb +25 -0
- data/lib/muwu/manifest_task/metadata.rb +35 -0
- data/lib/muwu/manifest_task/navigator.rb +29 -0
- data/lib/muwu/manifest_task/subcontents.rb +48 -0
- data/lib/muwu/manifest_task/text.rb +51 -0
- data/lib/muwu/manifest_task/text_item.rb +124 -0
- data/lib/muwu/manifest_task/title.rb +34 -0
- data/lib/muwu/manifest_task_builder/contents_builder.rb +88 -0
- data/lib/muwu/manifest_task_builder/document_css_builder.rb +63 -0
- data/lib/muwu/manifest_task_builder/document_html_builder.rb +210 -0
- data/lib/muwu/manifest_task_builder/document_js_builder.rb +69 -0
- data/lib/muwu/manifest_task_builder/metadata_builder.rb +118 -0
- data/lib/muwu/manifest_task_builder/navigator_builder.rb +78 -0
- data/lib/muwu/manifest_task_builder/subcontents_builder.rb +90 -0
- data/lib/muwu/manifest_task_builder/text_builder.rb +125 -0
- data/lib/muwu/manifest_task_builder/text_item_builder.rb +314 -0
- data/lib/muwu/manifest_task_builder/title_builder.rb +122 -0
- data/lib/muwu/project/project.rb +430 -0
- data/lib/muwu/project_builder/assets/config/css/base/html_elements.scss +138 -0
- data/lib/muwu/project_builder/assets/config/css/base/index.scss +11 -0
- data/lib/muwu/project_builder/assets/config/css/base/mixin_text_section_heading.scss +23 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_contents.scss +58 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_metadata.scss +17 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_navigator.scss +13 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_subcontents.scss +58 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_text.scss +48 -0
- data/lib/muwu/project_builder/assets/config/css/base/section_muwu_title.scss +22 -0
- data/lib/muwu/project_builder/assets/config/css/colors/dark.scss +32 -0
- data/lib/muwu/project_builder/assets/config/css/colors/index.scss +1 -0
- data/lib/muwu/project_builder/assets/config/css/colors/light.scss +34 -0
- data/lib/muwu/project_builder/assets/config/css/extensions/index.scss +1 -0
- data/lib/muwu/project_builder/assets/config/css/index.scss +19 -0
- data/lib/muwu/project_builder/assets/config/css_debugger/debug_section_text.scss +27 -0
- data/lib/muwu/project_builder/project_reader.rb +144 -0
- data/lib/muwu/project_builder/project_reset_css.rb +95 -0
- data/lib/muwu/project_builder/project_starter.rb +27 -0
- data/lib/muwu/project_builder/project_validator.rb +157 -0
- data/lib/muwu/project_builder/project_writer.rb +127 -0
- data/lib/muwu/project_exception/css_manifest_file_not_found.rb +23 -0
- data/lib/muwu/project_exception/dry_output_recommended_with_multiple_documents.rb +19 -0
- data/lib/muwu/project_exception/metadata_file_not_found.rb +24 -0
- data/lib/muwu/project_exception/metadata_value_not_given.rb +42 -0
- data/lib/muwu/project_exception/multiple_documents_outlined_with_stdout.rb +18 -0
- data/lib/muwu/project_exception/multiple_formats_requested_with_stdout.rb +18 -0
- data/lib/muwu/project_exception/navigator_not_recommended_with_stdout.rb +23 -0
- data/lib/muwu/project_exception/navigators_will_be_generated_automatically.rb +23 -0
- data/lib/muwu/project_exception/option_key_not_understood.rb +23 -0
- data/lib/muwu/project_exception/option_not_validatable.rb +23 -0
- data/lib/muwu/project_exception/option_value_not_understood.rb +24 -0
- data/lib/muwu/project_exception/options_file_not_found.rb +24 -0
- data/lib/muwu/project_exception/outline_file_not_found.rb +24 -0
- data/lib/muwu/project_exception/outline_step_not_understood.rb +23 -0
- data/lib/muwu/project_exception/output_already_open.rb +18 -0
- data/lib/muwu/project_exception/output_not_open.rb +18 -0
- data/lib/muwu/project_exception/subcontents_will_be_generated_automatically copy.rb +23 -0
- data/lib/muwu/project_exception/target_project_folder_already_exists.rb +24 -0
- data/lib/muwu/project_exception/text_source_file_not_found.rb +26 -0
- data/lib/muwu/project_exception_handler/fatal.rb +39 -0
- data/lib/muwu/project_options/project_options.rb +54 -0
- data/lib/muwu/project_options_builder/project_option_validator.rb +37 -0
- data/lib/muwu/project_options_builder/project_option_validator_key.rb +56 -0
- data/lib/muwu/project_options_builder/project_option_validator_value.rb +300 -0
- data/lib/muwu/project_options_builder/project_options_reader.rb +80 -0
- data/lib/muwu/render_concat/render_concat.rb +80 -0
- data/lib/muwu/render_html/render_html.rb +101 -0
- data/lib/muwu/render_html/render_markup_to_html.rb +87 -0
- data/lib/muwu/render_html_builder/render_css_builder.rb +34 -0
- data/lib/muwu/render_html_builder/render_html_builder.rb +34 -0
- data/lib/muwu/render_html_builder/render_js_builder.rb +34 -0
- data/lib/muwu/render_html_partial/js_library/_init_bare.js +7 -0
- data/lib/muwu/render_html_partial/js_library/_zepto.min.js +2 -0
- data/lib/muwu/render_html_partial/js_library/init.js +10 -0
- data/lib/muwu/render_html_partial/js_library/navigation.js +140 -0
- data/lib/muwu/render_html_partial/render_contents.rb +369 -0
- data/lib/muwu/render_html_partial/render_document_css.rb +45 -0
- data/lib/muwu/render_html_partial/render_document_html.rb +397 -0
- data/lib/muwu/render_html_partial/render_document_js.rb +37 -0
- data/lib/muwu/render_html_partial/render_js_library.rb +54 -0
- data/lib/muwu/render_html_partial/render_metadata.rb +120 -0
- data/lib/muwu/render_html_partial/render_navigator.rb +136 -0
- data/lib/muwu/render_html_partial/render_subcontents.rb +374 -0
- data/lib/muwu/render_html_partial/render_text.rb +74 -0
- data/lib/muwu/render_html_partial/render_text_item.rb +230 -0
- data/lib/muwu/render_html_partial/render_title.rb +71 -0
- data/lib/muwu/render_html_partial_builder/render_contents_builder.rb +100 -0
- data/lib/muwu/render_html_partial_builder/render_document_css_builder.rb +46 -0
- data/lib/muwu/render_html_partial_builder/render_document_html_builder.rb +211 -0
- data/lib/muwu/render_html_partial_builder/render_document_js_builder.rb +52 -0
- data/lib/muwu/render_html_partial_builder/render_metadata_builder.rb +47 -0
- data/lib/muwu/render_html_partial_builder/render_navigator_builder.rb +74 -0
- data/lib/muwu/render_html_partial_builder/render_subcontents_builder.rb +85 -0
- data/lib/muwu/render_html_partial_builder/render_text_builder.rb +86 -0
- data/lib/muwu/render_html_partial_builder/render_text_item_builder.rb +274 -0
- data/lib/muwu/render_html_partial_builder/render_title_builder.rb +47 -0
- data/lib/muwu/render_inspector/render_inspector.rb +224 -0
- data/lib/muwu/var/deflistdiv.rb +239 -0
- data/lib/muwu_loader.rb +35 -0
- data/test/what_no_tests.md +5 -0
- metadata +251 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
module Muwu
|
2
|
+
module ManifestTaskBuilders
|
3
|
+
class MetadataBuilder
|
4
|
+
|
5
|
+
|
6
|
+
include Muwu
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor(
|
11
|
+
:outline_fragment_metadata,
|
12
|
+
:parent_document,
|
13
|
+
:project,
|
14
|
+
:task
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
def self.build
|
19
|
+
builder = new
|
20
|
+
yield(builder)
|
21
|
+
builder.task
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@task = ManifestTask::Metadata.new
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def build_from_outline(outline_fragment_metadata, parent_document)
|
31
|
+
@destination = parent_document.destination
|
32
|
+
@outline_fragment_metadata = outline_fragment_metadata
|
33
|
+
@parent_document = parent_document
|
34
|
+
@project = parent_document.project
|
35
|
+
phase_1_set_parent
|
36
|
+
phase_1_set_project
|
37
|
+
phase_2_set_destination
|
38
|
+
phase_2_set_metadata
|
39
|
+
phase_3_validate_metadata_values_exist
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def phase_1_set_parent
|
44
|
+
@task.parent_document = @parent_document
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def phase_1_set_project
|
49
|
+
@task.project = @project
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def phase_2_set_destination
|
54
|
+
@task.destination = @destination
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def phase_2_set_metadata
|
59
|
+
@task.metadata = determine_metadata
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def phase_3_validate_metadata_values_exist
|
64
|
+
ProjectValidator.new(@project).validate_task_metadata(@task)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
|
72
|
+
def determine_metadata
|
73
|
+
case @outline_fragment_metadata
|
74
|
+
when String
|
75
|
+
determine_metadata_all
|
76
|
+
when Hash
|
77
|
+
determine_metadata_selected
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def determine_metadata_all
|
83
|
+
@project.metadata.merge(determine_metadata_date_of_this_edition)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def determine_metadata_selected
|
88
|
+
metadata = {}
|
89
|
+
keys = @outline_fragment_metadata.flatten[1]
|
90
|
+
keys.each do |key|
|
91
|
+
if key =~ RegexpLib.metadata_key_date_of_this_edition
|
92
|
+
metadata.merge!(determine_metadata_date_of_this_edition(key: key))
|
93
|
+
else
|
94
|
+
metadata.merge!(determine_metadata_selected_and_validate(key))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
metadata
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def determine_metadata_selected_and_validate(key)
|
102
|
+
metadata = @project.metadata.select { |k,v| k.downcase == key.downcase }
|
103
|
+
if metadata.empty?
|
104
|
+
metadata = {key => nil}
|
105
|
+
end
|
106
|
+
metadata
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def determine_metadata_date_of_this_edition(key: 'date of this edition')
|
111
|
+
metadata = {key => @project.metadata["date of this edition"]}
|
112
|
+
metadata
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Muwu
|
2
|
+
module ManifestTaskBuilders
|
3
|
+
class NavigatorBuilder
|
4
|
+
|
5
|
+
|
6
|
+
include Muwu
|
7
|
+
|
8
|
+
|
9
|
+
attr_accessor(
|
10
|
+
:document,
|
11
|
+
:navigator,
|
12
|
+
:outline_step,
|
13
|
+
:project
|
14
|
+
)
|
15
|
+
|
16
|
+
def self.build
|
17
|
+
builder = new
|
18
|
+
yield(builder)
|
19
|
+
builder.navigator
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@navigator = ManifestTask::Navigator.new
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def build_from_outline(document)
|
29
|
+
@document = document
|
30
|
+
@project = document.project
|
31
|
+
set_destination
|
32
|
+
set_document_home_index
|
33
|
+
set_document_next_index
|
34
|
+
set_document_prev_index
|
35
|
+
set_heading
|
36
|
+
set_index
|
37
|
+
set_project
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def set_destination
|
42
|
+
@navigator.destination = @document.destination
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def set_document_home_index
|
47
|
+
@navigator.document_home_index = 0
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def set_document_next_index
|
52
|
+
@navigator.document_next_index = (@document.index + 1) % @project.outline.length
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def set_document_prev_index
|
57
|
+
@navigator.document_prev_index = (@document.index - 1) % @project.outline.length
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def set_heading
|
62
|
+
@navigator.heading = @project.title
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def set_index
|
67
|
+
@navigator.index = @document.index
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def set_project
|
72
|
+
@navigator.project = @project
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Muwu
|
2
|
+
module ManifestTaskBuilders
|
3
|
+
class SubcontentsBuilder
|
4
|
+
|
5
|
+
|
6
|
+
include Muwu
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor(
|
11
|
+
:manifest_subcontents,
|
12
|
+
:outline_subcontents,
|
13
|
+
:parent_document,
|
14
|
+
:project
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
def self.build
|
19
|
+
builder = new
|
20
|
+
yield(builder)
|
21
|
+
builder.manifest_subcontents
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@manifest_subcontents = ManifestTask::Subcontents.new
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def build_from_document(outline_step, parent_document)
|
31
|
+
@outline_subcontents = outline_step
|
32
|
+
@parent_document = parent_document
|
33
|
+
@project = parent_document.project
|
34
|
+
phase_1_set_parent
|
35
|
+
phase_1_set_project
|
36
|
+
phase_2_set_destination
|
37
|
+
phase_2_set_text_root_name
|
38
|
+
phase_3_set_item_depth_max
|
39
|
+
phase_3_set_will_render_section_numbers
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def phase_1_set_parent
|
44
|
+
@manifest_subcontents.parent = @parent_document
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def phase_1_set_project
|
49
|
+
@manifest_subcontents.project = @project
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def phase_2_set_destination
|
54
|
+
@manifest_subcontents.destination = @parent_document.destination
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def phase_2_set_text_root_name
|
59
|
+
@manifest_subcontents.text_root_name = determine_text_root_name
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def phase_3_set_item_depth_max
|
64
|
+
@manifest_subcontents.item_depth_max = @project.options.render_sections_distinctly_depth_max
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def phase_3_set_will_render_section_numbers
|
69
|
+
@manifest_subcontents.will_render_section_numbers = @project.options.render_section_numbers
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
|
77
|
+
def determine_text_root_name
|
78
|
+
components = @outline_subcontents.partition(RegexpLib.outline_text_plus_whitespace)
|
79
|
+
text_block_name = components[2].to_s.downcase.strip
|
80
|
+
if text_block_name == ''
|
81
|
+
text_block_name = @project.default_text_block_name
|
82
|
+
end
|
83
|
+
text_block_name
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Muwu
|
2
|
+
module ManifestTaskBuilders
|
3
|
+
class TextBuilder
|
4
|
+
|
5
|
+
|
6
|
+
include Muwu
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor(
|
11
|
+
:outline_text,
|
12
|
+
:parent_document,
|
13
|
+
:project,
|
14
|
+
:text
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
def self.build
|
19
|
+
builder = new
|
20
|
+
yield(builder)
|
21
|
+
builder.text
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@text = ManifestTask::Text.new
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def build_from_outline(outline_text, parent_document)
|
31
|
+
@outline_text = outline_text
|
32
|
+
@parent_document = parent_document
|
33
|
+
@project = parent_document.project
|
34
|
+
set_project
|
35
|
+
set_destination
|
36
|
+
set_naming
|
37
|
+
set_numbering
|
38
|
+
set_sections
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def set_destination
|
43
|
+
@text.destination = @parent_document.destination
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def set_naming
|
48
|
+
@text.naming = [determine_text_block_name]
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def set_numbering
|
53
|
+
@text.numbering = []
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def set_project
|
58
|
+
@text.project = @project
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def set_sections
|
63
|
+
@text.sections = build_sections
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
|
71
|
+
def build_sections
|
72
|
+
sections = []
|
73
|
+
child_steps = determine_text_block_steps
|
74
|
+
if child_steps.empty? == false
|
75
|
+
child_section_numbering = section_number_extend(@text.numbering)
|
76
|
+
child_steps.each do |step|
|
77
|
+
child_section_numbering = section_number_find(child_section_numbering, step)
|
78
|
+
sections << build_text_item(step, child_section_numbering)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
sections
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def build_text_item(step, section_numbering)
|
86
|
+
ManifestTaskBuilders::TextItemBuilder.build do |b|
|
87
|
+
b.build_from_outline_fragment_text(step, section_numbering, @text)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def determine_text_block_name
|
93
|
+
directive = @outline_text.flatten[0]
|
94
|
+
components = directive.partition(RegexpLib.outline_text_plus_whitespace)
|
95
|
+
text_block_name = components[2].to_s.downcase.strip
|
96
|
+
if text_block_name == ''
|
97
|
+
text_block_name = @project.default_text_block_name
|
98
|
+
end
|
99
|
+
text_block_name
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def determine_text_block_steps
|
104
|
+
@outline_text.flatten[1]
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def section_number_extend(number_incoming)
|
109
|
+
number_outgoing = number_incoming.clone
|
110
|
+
number_outgoing << 0
|
111
|
+
number_outgoing
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def section_number_find(number_incoming, step)
|
116
|
+
number_outgoing = number_incoming.clone
|
117
|
+
sorted_outline_steps = @project.outline_text_blocks_named(@text.text_root_name)
|
118
|
+
number_outgoing[-1] = sorted_outline_steps.index(step) + 1
|
119
|
+
number_outgoing
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
module Muwu
|
2
|
+
module ManifestTaskBuilders
|
3
|
+
class TextItemBuilder
|
4
|
+
|
5
|
+
|
6
|
+
include Muwu
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor(
|
11
|
+
:heading_data,
|
12
|
+
:numbering,
|
13
|
+
:outline_fragment,
|
14
|
+
:parent_manifest_text,
|
15
|
+
:project,
|
16
|
+
:source_filename,
|
17
|
+
:text_item
|
18
|
+
)
|
19
|
+
|
20
|
+
|
21
|
+
def self.build
|
22
|
+
builder = new
|
23
|
+
yield(builder)
|
24
|
+
builder.text_item
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@text_item = ManifestTask::TextItem.new
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def build_from_outline_fragment_text(outline_fragment, numbering, parent_manifest_text)
|
34
|
+
@numbering = numbering
|
35
|
+
@outline_fragment = outline_fragment
|
36
|
+
@parent_manifest_text = parent_manifest_text
|
37
|
+
@project = parent_manifest_text.project
|
38
|
+
phase_1_set_project
|
39
|
+
phase_2_set_source_filename
|
40
|
+
phase_3_set_heading
|
41
|
+
phase_4_set_destination
|
42
|
+
phase_4_set_naming
|
43
|
+
phase_4_set_numbering
|
44
|
+
phase_5_set_sections
|
45
|
+
phase_6_validate_file_presence
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def phase_1_set_project
|
50
|
+
@text_item.project = @project
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def phase_2_set_source_filename
|
55
|
+
@source_filename = determine_source_filename
|
56
|
+
@text_item.source_filename = @source_filename
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def phase_3_set_heading
|
61
|
+
@heading_data = determine_heading_data
|
62
|
+
@text_item.heading = @heading_data[:heading]
|
63
|
+
@text_item.heading_origin = @heading_data[:origin]
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def phase_4_set_destination
|
68
|
+
@text_item.destination = @parent_manifest_text.destination
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def phase_4_set_naming
|
73
|
+
if Hash === @outline_fragment
|
74
|
+
@text_item.naming = [@parent_manifest_text.naming, SanitizerHelper.sanitize_text_item_path(outline_step)].flatten
|
75
|
+
else
|
76
|
+
@text_item.naming = [@parent_manifest_text.naming, @heading_data[:heading]].flatten
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def phase_4_set_numbering
|
82
|
+
@text_item.numbering = @numbering
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def phase_5_set_sections
|
87
|
+
if Hash === @outline_fragment
|
88
|
+
@text_item.sections = determine_sections
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def phase_6_validate_file_presence
|
94
|
+
ProjectValidator.new(@project).validate_task_text_item(@text_item)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
|
102
|
+
def build_text_item(step, section_numbering)
|
103
|
+
ManifestTaskBuilders::TextItemBuilder.build do |b|
|
104
|
+
b.build_from_outline_fragment_text(step, section_numbering, @text_item)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def determine_child_steps_from_outline
|
110
|
+
[@outline_step.flatten[1]].flatten
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def determine_sections
|
115
|
+
sections = []
|
116
|
+
child_steps = [@outline_fragment.flatten[1]].flatten
|
117
|
+
if child_steps.empty? == false
|
118
|
+
child_section_numbering = section_number_extend(@text_item.numbering)
|
119
|
+
child_steps.each do |step|
|
120
|
+
child_section_numbering = section_number_increment(child_section_numbering)
|
121
|
+
sections << build_text_item(step, child_section_numbering)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
sections
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def determine_source_filename
|
129
|
+
if @project.outline_text_pathnames_are_explicit
|
130
|
+
determine_source_filename_explicitly
|
131
|
+
elsif @project.outline_text_pathnames_are_flexible
|
132
|
+
determine_source_filename_flexibly
|
133
|
+
elsif @project.outline_text_pathnames_are_implicit
|
134
|
+
determine_source_filename_implicitly
|
135
|
+
else
|
136
|
+
determine_source_filename_explicitly
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def determine_source_filename_explicitly
|
142
|
+
filename = SanitizerHelper.sanitize_text_item_basename(outline_step)
|
143
|
+
filepath = ['text']
|
144
|
+
File.join([filepath, filename].flatten)
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def determine_source_filename_flexibly
|
149
|
+
if OutlineHelper.new(outline_step).text_step_flexible_suggests_file
|
150
|
+
determine_source_filename_explicitly
|
151
|
+
else
|
152
|
+
determine_source_filename_implicitly
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def determine_source_filename_implicitly
|
158
|
+
# filename = make_filename_implicitly(outline_step)
|
159
|
+
# filepath = make_filepath_implicitly
|
160
|
+
# File.join([filepath, filename].flatten)
|
161
|
+
determine_source_filename_cascade_implicitly
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
def determine_source_filename_cascade_implicitly
|
166
|
+
source_filename = ''
|
167
|
+
file_path = make_filepath_implicitly
|
168
|
+
file_basename = SanitizerHelper.sanitize_text_item_path(outline_step)
|
169
|
+
file_name_md = file_basename + '.md'
|
170
|
+
file_name_haml = file_basename + '.haml'
|
171
|
+
file_attempt_md = File.join([file_path, file_name_md].flatten)
|
172
|
+
file_attempt_haml = File.join([file_path, file_name_haml].flatten)
|
173
|
+
if File.exists?(file_attempt_md)
|
174
|
+
source_filename = file_attempt_md
|
175
|
+
elsif File.exists?(file_attempt_haml)
|
176
|
+
source_filename = file_attempt_haml
|
177
|
+
else
|
178
|
+
source_filename = file_attempt_md
|
179
|
+
end
|
180
|
+
source_filename
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def determine_heading_data
|
185
|
+
if @text_item.source_file_does_exist
|
186
|
+
determine_heading_from_file
|
187
|
+
elsif @text_item.source_file_does_not_exist
|
188
|
+
determine_heading_from_file_basename_or_outline
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
def determine_heading_from_file
|
194
|
+
case File.extname(@text_item.source_filename_absolute).downcase
|
195
|
+
when '.haml'
|
196
|
+
determine_heading_from_file_haml
|
197
|
+
when '.md'
|
198
|
+
determine_heading_from_file_md
|
199
|
+
else
|
200
|
+
determine_heading_from_file_basename
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
def determine_heading_from_file_basename
|
206
|
+
heading = File.basename(@text_item.source_filename, '.*')
|
207
|
+
origin = :basename
|
208
|
+
{ heading: heading, origin: origin }
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
def determine_heading_from_file_basename_or_outline
|
213
|
+
case @project.outline_text_pathnames
|
214
|
+
when 'explicit'
|
215
|
+
heading = File.basename(@text_item.source_filename, '.*')
|
216
|
+
origin = :basename
|
217
|
+
when 'flexible', 'implicit'
|
218
|
+
heading = outline_step
|
219
|
+
origin = :outline
|
220
|
+
else
|
221
|
+
heading = ''
|
222
|
+
origin = nil
|
223
|
+
end
|
224
|
+
{ heading: heading, origin: origin }
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
def determine_heading_from_file_haml
|
229
|
+
first_line = File.open(@text_item.source_filename_absolute, 'r') { |f| f.gets("\n").to_s }
|
230
|
+
if first_line =~ RegexpLib.haml_heading
|
231
|
+
determine_heading_from_file_haml_first_line(first_line)
|
232
|
+
else
|
233
|
+
determine_heading_from_file_basename_or_outline
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
def determine_heading_from_file_haml_first_line(first_line)
|
239
|
+
heading = first_line.gsub(RegexpLib.haml_heading_plus_whitespace,'').strip
|
240
|
+
origin = :text_source
|
241
|
+
{ heading: heading, origin: origin }
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
def determine_heading_from_file_md
|
246
|
+
first_line = File.open(@text_item.source_filename_absolute, 'r') { |f| f.gets("\n").to_s }
|
247
|
+
if first_line =~ RegexpLib.markdown_heading
|
248
|
+
determine_heading_from_file_md_first_line(first_line)
|
249
|
+
else
|
250
|
+
determine_heading_from_file_basename_or_outline
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
|
255
|
+
def determine_heading_from_file_md_first_line(first_line)
|
256
|
+
heading = first_line.gsub(RegexpLib.markdown_heading_plus_whitespace,'').strip
|
257
|
+
origin = :text_source
|
258
|
+
{ heading: heading, origin: origin }
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
# def make_filename_implicitly(string)
|
263
|
+
# file_basename = SanitizerHelper.sanitize_text_item_path(string)
|
264
|
+
# filename = file_basename + '.md'
|
265
|
+
# filename
|
266
|
+
# end
|
267
|
+
|
268
|
+
|
269
|
+
def make_filepath_implicitly
|
270
|
+
path_from_project_home = ['text']
|
271
|
+
if @project.text_block_naming_is_simple
|
272
|
+
path_from_project_home.concat(@parent_manifest_text.naming_downcase_without_text_root)
|
273
|
+
elsif @project.text_block_naming_is_not_simple
|
274
|
+
path_from_project_home.concat(@parent_manifest_text.naming_downcase)
|
275
|
+
end
|
276
|
+
safe_path_from_project_home = SanitizerHelper.sanitize_text_item_path(path_from_project_home)
|
277
|
+
safe_path_from_project_home
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
def outline_step
|
283
|
+
case @outline_fragment
|
284
|
+
when Hash
|
285
|
+
@outline_fragment.flatten[0].to_s
|
286
|
+
else
|
287
|
+
@outline_fragment.to_s
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
def outline_step_sanitized
|
293
|
+
SanitizerHelper.sanitize_text_item_path(outline_step)
|
294
|
+
end
|
295
|
+
|
296
|
+
|
297
|
+
def section_number_extend(number_incoming)
|
298
|
+
number_outgoing = number_incoming.clone
|
299
|
+
number_outgoing << 0
|
300
|
+
number_outgoing
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
def section_number_increment(number_incoming)
|
305
|
+
number_outgoing = number_incoming.clone
|
306
|
+
number_outgoing[-1] = number_outgoing[-1].next
|
307
|
+
number_outgoing
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|