muwu 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/bin/muwu +5 -0
  3. data/lib/muwu.rb +38 -0
  4. data/lib/muwu/cli/cli.rb +143 -0
  5. data/lib/muwu/cli/cli_help.rb +28 -0
  6. data/lib/muwu/cli/help/compile +22 -0
  7. data/lib/muwu/cli/help/concat +8 -0
  8. data/lib/muwu/cli/help/heading +2 -0
  9. data/lib/muwu/cli/help/inspect +7 -0
  10. data/lib/muwu/cli/help/new +8 -0
  11. data/lib/muwu/cli/help/reset +14 -0
  12. data/lib/muwu/cli/help/summary +14 -0
  13. data/lib/muwu/controller/controller.rb +120 -0
  14. data/lib/muwu/controller/controller_interaction.rb +146 -0
  15. data/lib/muwu/default/default.rb +51 -0
  16. data/lib/muwu/destination/destination.rb +212 -0
  17. data/lib/muwu/destination_builder/destination_builder.rb +127 -0
  18. data/lib/muwu/helper/hash_helper.rb +37 -0
  19. data/lib/muwu/helper/html_href_helper.rb +101 -0
  20. data/lib/muwu/helper/outline_helper.rb +160 -0
  21. data/lib/muwu/helper/regexp_lib.rb +101 -0
  22. data/lib/muwu/helper/sanitizer_helper.rb +50 -0
  23. data/lib/muwu/manifest/manifest.rb +158 -0
  24. data/lib/muwu/manifest_builder/manifest_builder.rb +102 -0
  25. data/lib/muwu/manifest_task/contents.rb +42 -0
  26. data/lib/muwu/manifest_task/document_css.rb +25 -0
  27. data/lib/muwu/manifest_task/document_html.rb +69 -0
  28. data/lib/muwu/manifest_task/document_js.rb +25 -0
  29. data/lib/muwu/manifest_task/metadata.rb +35 -0
  30. data/lib/muwu/manifest_task/navigator.rb +29 -0
  31. data/lib/muwu/manifest_task/subcontents.rb +48 -0
  32. data/lib/muwu/manifest_task/text.rb +51 -0
  33. data/lib/muwu/manifest_task/text_item.rb +124 -0
  34. data/lib/muwu/manifest_task/title.rb +34 -0
  35. data/lib/muwu/manifest_task_builder/contents_builder.rb +88 -0
  36. data/lib/muwu/manifest_task_builder/document_css_builder.rb +63 -0
  37. data/lib/muwu/manifest_task_builder/document_html_builder.rb +210 -0
  38. data/lib/muwu/manifest_task_builder/document_js_builder.rb +69 -0
  39. data/lib/muwu/manifest_task_builder/metadata_builder.rb +118 -0
  40. data/lib/muwu/manifest_task_builder/navigator_builder.rb +78 -0
  41. data/lib/muwu/manifest_task_builder/subcontents_builder.rb +90 -0
  42. data/lib/muwu/manifest_task_builder/text_builder.rb +125 -0
  43. data/lib/muwu/manifest_task_builder/text_item_builder.rb +314 -0
  44. data/lib/muwu/manifest_task_builder/title_builder.rb +122 -0
  45. data/lib/muwu/project/project.rb +430 -0
  46. data/lib/muwu/project_builder/assets/config/css/base/html_elements.scss +138 -0
  47. data/lib/muwu/project_builder/assets/config/css/base/index.scss +11 -0
  48. data/lib/muwu/project_builder/assets/config/css/base/mixin_text_section_heading.scss +23 -0
  49. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_contents.scss +58 -0
  50. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_metadata.scss +17 -0
  51. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_navigator.scss +13 -0
  52. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_subcontents.scss +58 -0
  53. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_text.scss +48 -0
  54. data/lib/muwu/project_builder/assets/config/css/base/section_muwu_title.scss +22 -0
  55. data/lib/muwu/project_builder/assets/config/css/colors/dark.scss +32 -0
  56. data/lib/muwu/project_builder/assets/config/css/colors/index.scss +1 -0
  57. data/lib/muwu/project_builder/assets/config/css/colors/light.scss +34 -0
  58. data/lib/muwu/project_builder/assets/config/css/extensions/index.scss +1 -0
  59. data/lib/muwu/project_builder/assets/config/css/index.scss +19 -0
  60. data/lib/muwu/project_builder/assets/config/css_debugger/debug_section_text.scss +27 -0
  61. data/lib/muwu/project_builder/project_reader.rb +144 -0
  62. data/lib/muwu/project_builder/project_reset_css.rb +95 -0
  63. data/lib/muwu/project_builder/project_starter.rb +27 -0
  64. data/lib/muwu/project_builder/project_validator.rb +157 -0
  65. data/lib/muwu/project_builder/project_writer.rb +127 -0
  66. data/lib/muwu/project_exception/css_manifest_file_not_found.rb +23 -0
  67. data/lib/muwu/project_exception/dry_output_recommended_with_multiple_documents.rb +19 -0
  68. data/lib/muwu/project_exception/metadata_file_not_found.rb +24 -0
  69. data/lib/muwu/project_exception/metadata_value_not_given.rb +42 -0
  70. data/lib/muwu/project_exception/multiple_documents_outlined_with_stdout.rb +18 -0
  71. data/lib/muwu/project_exception/multiple_formats_requested_with_stdout.rb +18 -0
  72. data/lib/muwu/project_exception/navigator_not_recommended_with_stdout.rb +23 -0
  73. data/lib/muwu/project_exception/navigators_will_be_generated_automatically.rb +23 -0
  74. data/lib/muwu/project_exception/option_key_not_understood.rb +23 -0
  75. data/lib/muwu/project_exception/option_not_validatable.rb +23 -0
  76. data/lib/muwu/project_exception/option_value_not_understood.rb +24 -0
  77. data/lib/muwu/project_exception/options_file_not_found.rb +24 -0
  78. data/lib/muwu/project_exception/outline_file_not_found.rb +24 -0
  79. data/lib/muwu/project_exception/outline_step_not_understood.rb +23 -0
  80. data/lib/muwu/project_exception/output_already_open.rb +18 -0
  81. data/lib/muwu/project_exception/output_not_open.rb +18 -0
  82. data/lib/muwu/project_exception/subcontents_will_be_generated_automatically copy.rb +23 -0
  83. data/lib/muwu/project_exception/target_project_folder_already_exists.rb +24 -0
  84. data/lib/muwu/project_exception/text_source_file_not_found.rb +26 -0
  85. data/lib/muwu/project_exception_handler/fatal.rb +39 -0
  86. data/lib/muwu/project_options/project_options.rb +54 -0
  87. data/lib/muwu/project_options_builder/project_option_validator.rb +37 -0
  88. data/lib/muwu/project_options_builder/project_option_validator_key.rb +56 -0
  89. data/lib/muwu/project_options_builder/project_option_validator_value.rb +300 -0
  90. data/lib/muwu/project_options_builder/project_options_reader.rb +80 -0
  91. data/lib/muwu/render_concat/render_concat.rb +80 -0
  92. data/lib/muwu/render_html/render_html.rb +101 -0
  93. data/lib/muwu/render_html/render_markup_to_html.rb +87 -0
  94. data/lib/muwu/render_html_builder/render_css_builder.rb +34 -0
  95. data/lib/muwu/render_html_builder/render_html_builder.rb +34 -0
  96. data/lib/muwu/render_html_builder/render_js_builder.rb +34 -0
  97. data/lib/muwu/render_html_partial/js_library/_init_bare.js +7 -0
  98. data/lib/muwu/render_html_partial/js_library/_zepto.min.js +2 -0
  99. data/lib/muwu/render_html_partial/js_library/init.js +10 -0
  100. data/lib/muwu/render_html_partial/js_library/navigation.js +140 -0
  101. data/lib/muwu/render_html_partial/render_contents.rb +369 -0
  102. data/lib/muwu/render_html_partial/render_document_css.rb +45 -0
  103. data/lib/muwu/render_html_partial/render_document_html.rb +397 -0
  104. data/lib/muwu/render_html_partial/render_document_js.rb +37 -0
  105. data/lib/muwu/render_html_partial/render_js_library.rb +54 -0
  106. data/lib/muwu/render_html_partial/render_metadata.rb +120 -0
  107. data/lib/muwu/render_html_partial/render_navigator.rb +136 -0
  108. data/lib/muwu/render_html_partial/render_subcontents.rb +374 -0
  109. data/lib/muwu/render_html_partial/render_text.rb +74 -0
  110. data/lib/muwu/render_html_partial/render_text_item.rb +230 -0
  111. data/lib/muwu/render_html_partial/render_title.rb +71 -0
  112. data/lib/muwu/render_html_partial_builder/render_contents_builder.rb +100 -0
  113. data/lib/muwu/render_html_partial_builder/render_document_css_builder.rb +46 -0
  114. data/lib/muwu/render_html_partial_builder/render_document_html_builder.rb +211 -0
  115. data/lib/muwu/render_html_partial_builder/render_document_js_builder.rb +52 -0
  116. data/lib/muwu/render_html_partial_builder/render_metadata_builder.rb +47 -0
  117. data/lib/muwu/render_html_partial_builder/render_navigator_builder.rb +74 -0
  118. data/lib/muwu/render_html_partial_builder/render_subcontents_builder.rb +85 -0
  119. data/lib/muwu/render_html_partial_builder/render_text_builder.rb +86 -0
  120. data/lib/muwu/render_html_partial_builder/render_text_item_builder.rb +274 -0
  121. data/lib/muwu/render_html_partial_builder/render_title_builder.rb +47 -0
  122. data/lib/muwu/render_inspector/render_inspector.rb +224 -0
  123. data/lib/muwu/var/deflistdiv.rb +239 -0
  124. data/lib/muwu_loader.rb +35 -0
  125. data/test/what_no_tests.md +5 -0
  126. metadata +251 -0
@@ -0,0 +1,80 @@
1
+ module Muwu
2
+ class ProjectOptionsReader
3
+
4
+
5
+ include Muwu
6
+
7
+
8
+ require 'yaml'
9
+
10
+
11
+ attr_accessor(
12
+ :options_from_file,
13
+ :options_validated,
14
+ :project_options
15
+ )
16
+
17
+
18
+ def self.build
19
+ builder = new
20
+ yield(builder)
21
+ builder.project_options
22
+ end
23
+
24
+
25
+ def initialize
26
+ @options_from_file = {}
27
+ @options_validated = {}
28
+ @project_options = ProjectOptions.new
29
+ end
30
+
31
+
32
+
33
+ public
34
+
35
+
36
+ def build_from_ymlfile(project)
37
+ @project = project
38
+ phase_1_read_options_file
39
+ phase_2_validate_options_file
40
+ phase_3_set_project_options
41
+ end
42
+
43
+
44
+ def phase_1_read_options_file
45
+ if ProjectValidator.new(@project).validate_file_options
46
+ @options_from_file = YAML.load_file(@project.options_filename)
47
+ end
48
+ end
49
+
50
+
51
+ def phase_2_validate_options_file
52
+ @options_validated = validate_options(@options_from_file)
53
+ end
54
+
55
+
56
+ def phase_3_set_project_options
57
+ @options_validated.each_pair do |key, value|
58
+ @project_options.set_option(key, value)
59
+ end
60
+ end
61
+
62
+
63
+
64
+ private
65
+
66
+
67
+ def validate_options(options)
68
+ result = {}
69
+ options.each_pair do |key, value|
70
+ valid_option = ProjectOptionValidator.new_if_valid_key(key, value, @project)
71
+ if valid_option
72
+ result[valid_option.key] = valid_option.value
73
+ end
74
+ end
75
+ result.reject { |k,v| (v == nil) || (v == '') }
76
+ end
77
+
78
+
79
+ end
80
+ end
@@ -0,0 +1,80 @@
1
+ module Muwu
2
+ class RenderConcat
3
+
4
+
5
+ def initialize(project)
6
+ @output_path = project.working_directory
7
+ @output_filename = project.html_basename + '.md'
8
+ @project = project
9
+ @manifest = project.manifest
10
+ end
11
+
12
+
13
+ public
14
+
15
+
16
+ def render
17
+ destination = File.join(@output_path, @output_filename)
18
+ File.open(destination, 'w') do |f|
19
+ @manifest.text_blocks.each do |text|
20
+ text.sections.each do |text_item|
21
+ render_text_item(f, text_item)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ def render_text_item(f, text_item)
29
+ render_text_item_head(f, text_item)
30
+ render_text_item_source(f, text_item)
31
+ render_text_item_sections(f, text_item)
32
+ end
33
+
34
+
35
+ def render_text_item_head(f, text_item)
36
+ f.puts '# ' + text_item.numbering.join('.')
37
+ if heading_origin_is_basename_or_outline(text_item)
38
+ f.puts '# ' + text_item.heading
39
+ f.puts "\n"
40
+ end
41
+ end
42
+
43
+
44
+ def render_text_item_sections(f, text_item)
45
+ if text_item.does_have_child_sections
46
+ text_item.sections.each do |ti|
47
+ render_text_item(f, ti)
48
+ end
49
+ render_text_item_spacer(f, text_item)
50
+ end
51
+ end
52
+
53
+
54
+ def render_text_item_source(f, text_item)
55
+ if text_item.source_file_does_exist
56
+ f.puts text_item.source.strip
57
+ end
58
+ render_text_item_spacer(f, text_item)
59
+ end
60
+
61
+
62
+ def render_text_item_spacer(f, text_item)
63
+ f.puts "\n\n\n\n"
64
+ end
65
+
66
+
67
+
68
+ private
69
+
70
+
71
+ def heading_origin_is_basename_or_outline(text_item)
72
+ [:basename, :outline].include?(text_item.heading_origin)
73
+ end
74
+
75
+
76
+
77
+
78
+ end
79
+ end
80
+
@@ -0,0 +1,101 @@
1
+ module Muwu
2
+ class RenderHtml
3
+
4
+
5
+ include Muwu
6
+
7
+
8
+ def initialize(project)
9
+ @manifest = project.manifest
10
+ @project = project
11
+ halt_if_project_has_fatal_exceptions
12
+ end
13
+
14
+
15
+
16
+ public
17
+
18
+
19
+ def render
20
+ if @manifest.does_have_documents
21
+ build_and_render(@manifest.documents)
22
+ else
23
+ reply_nothing_to_do
24
+ end
25
+ end
26
+
27
+
28
+ def render_css_only
29
+ if @manifest.does_have_documents_css
30
+ build_and_render(@manifest.documents_css)
31
+ else
32
+ reply_nothing_to_do
33
+ end
34
+ end
35
+
36
+
37
+ def render_html_by_index(index)
38
+ document_html = @manifest.find_document_html_by_index(index)
39
+ if document_html
40
+ build_and_render(document_html)
41
+ else
42
+ reply_nothing_to_do
43
+ end
44
+ end
45
+
46
+
47
+ def render_html_only
48
+ if @manifest.does_have_documents_html
49
+ build_and_render(@manifest.documents_html)
50
+ else
51
+ reply_nothing_to_do
52
+ end
53
+ end
54
+
55
+
56
+ def render_js_only
57
+ if @manifest.does_have_documents_js
58
+ build_and_render(@manifest.documents_js)
59
+ else
60
+ reply_nothing_to_do
61
+ end
62
+ end
63
+
64
+
65
+
66
+ private
67
+
68
+
69
+ def build_and_render(document)
70
+ case document
71
+ when Array
72
+ document.each { |d| build_and_render(d) }
73
+
74
+ when ManifestTask::DocumentCss
75
+ RenderCssBuilder.new(document).build_and_render
76
+
77
+ when ManifestTask::DocumentHtml
78
+ RenderHtmlBuilder.new(document).build_and_render
79
+
80
+ when ManifestTask::DocumentJs
81
+ RenderJsBuilder.new(document).build_and_render
82
+ end
83
+ end
84
+
85
+
86
+ def halt_if_project_has_fatal_exceptions
87
+ begin
88
+ if @project.exceptions_fatal.any?
89
+ raise ProjectExceptionHandler::Fatal.new(@project.exceptions_fatal)
90
+ end
91
+ end
92
+ end
93
+
94
+
95
+ def reply_nothing_to_do
96
+ $stderr.puts '- No documents to compile.'
97
+ end
98
+
99
+
100
+ end
101
+ end
@@ -0,0 +1,87 @@
1
+ module Muwu
2
+ class RenderMarkupToHtml
3
+
4
+
5
+ require 'cgi'
6
+ require 'commonmarker'
7
+ require 'haml'
8
+ require 'motion-markdown-it'
9
+ require 'motion-markdown-it-plugins'
10
+
11
+
12
+
13
+ def initialize(project)
14
+ @project = project
15
+ end
16
+
17
+
18
+
19
+ public
20
+
21
+
22
+ def render(filename)
23
+ case File.extname(filename).downcase
24
+ when '.md'
25
+ render_md(filename)
26
+ when '.haml'
27
+ render_haml(filename)
28
+ end
29
+ end
30
+
31
+
32
+
33
+ private
34
+
35
+
36
+ def read_haml_text(filename)
37
+ File.read(filename)
38
+ end
39
+
40
+
41
+ def read_markdown_text(filename)
42
+ if @project.options.markdown_allows_raw_html == true
43
+ File.read(filename)
44
+ else
45
+ CGI.escapeHTML(File.read(filename))
46
+ end
47
+ end
48
+
49
+
50
+ def render_haml(filename)
51
+ text = read_haml_text(filename)
52
+ Haml::Engine.new(text, {suppress_eval: true}).render
53
+ end
54
+
55
+
56
+ def render_md(filename)
57
+ text = read_markdown_text(filename)
58
+ case @project.options.markdown_renderer
59
+ when 'commonmarker'
60
+ render_md_commonmarker(text)
61
+ when 'motion-markdown-it'
62
+ render_md_motion_markdown_it(text)
63
+ end
64
+ end
65
+
66
+
67
+ def render_md_commonmarker(text)
68
+ if @project.options.render_punctuation_smart
69
+ CommonMarker.render_doc(text, :SMART).to_html
70
+ else
71
+ CommonMarker.render_doc(text, :DEFAULT).to_html
72
+ end
73
+ end
74
+
75
+
76
+ def render_md_motion_markdown_it(text)
77
+ if @project.options.render_punctuation_smart
78
+ MarkdownIt::Parser.new({html: true, typographer: true}).use(Muwu::Var::MotionMarkdownItPlugins::Deflistdiv).render(text)
79
+ else
80
+ MarkdownIt::Parser.new({html: true}).use(Muwu::Var::MotionMarkdownItPlugins::Deflistdiv).render(text)
81
+ end
82
+ end
83
+
84
+
85
+
86
+ end
87
+ end
@@ -0,0 +1,34 @@
1
+ module Muwu
2
+ class RenderCssBuilder
3
+
4
+
5
+ include Muwu
6
+
7
+
8
+ def initialize(document)
9
+ @document = document
10
+ end
11
+
12
+
13
+ def build_and_render
14
+ if ManifestTask::DocumentCss === @document
15
+ build_document_css.render
16
+ end
17
+ end
18
+
19
+
20
+
21
+ private
22
+
23
+
24
+ def build_document_css
25
+ RenderHtmlPartialBuilder::DocumentCssBuilder.build do |b|
26
+ b.build_from_manifest_document(@document)
27
+ end
28
+ end
29
+
30
+
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,34 @@
1
+ module Muwu
2
+ class RenderHtmlBuilder
3
+
4
+
5
+ include Muwu
6
+
7
+
8
+ def initialize(document)
9
+ @document = document
10
+ end
11
+
12
+
13
+ def build_and_render
14
+ if ManifestTask::DocumentHtml === @document
15
+ build_document_html.render
16
+ end
17
+ end
18
+
19
+
20
+
21
+ private
22
+
23
+
24
+ def build_document_html
25
+ RenderHtmlPartialBuilder::DocumentHtmlBuilder.build do |b|
26
+ b.build_from_manifest_document(@document)
27
+ end
28
+ end
29
+
30
+
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,34 @@
1
+ module Muwu
2
+ class RenderJsBuilder
3
+
4
+
5
+ include Muwu
6
+
7
+
8
+ def initialize(document)
9
+ @document = document
10
+ end
11
+
12
+
13
+ def build_and_render
14
+ if ManifestTask::DocumentJs === @document
15
+ build_document_js.render
16
+ end
17
+ end
18
+
19
+
20
+
21
+ private
22
+
23
+
24
+ def build_document_js
25
+ RenderHtmlPartialBuilder::DocumentJsBuilder.build do |b|
26
+ b.build_from_manifest_document(@document)
27
+ end
28
+ end
29
+
30
+
31
+ end
32
+ end
33
+
34
+