middleman-presentation-core 0.16.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +7 -0
  2. data/.rdebugrc +7 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +52 -0
  5. data/.simplecov +25 -0
  6. data/.yardopts +5 -0
  7. data/Guardfile +13 -0
  8. data/LICENSE.software +21 -0
  9. data/Rakefile +200 -0
  10. data/config/license_finder.yml +13 -0
  11. data/cucumber.yml +2 -0
  12. data/doc/licenses/dependencies.csv +55 -0
  13. data/doc/licenses/dependencies.db +0 -0
  14. data/doc/licenses/dependencies.html +1415 -0
  15. data/doc/licenses/dependencies.md +603 -0
  16. data/doc/licenses/dependencies_detailed.csv +190 -0
  17. data/doc/yard/.keep +0 -0
  18. data/features/build_presentation.feature +62 -0
  19. data/features/code_highlighting.feature +43 -0
  20. data/features/components.feature +29 -0
  21. data/features/create_plugin-cli.feature +11 -0
  22. data/features/create_presentation-cli.feature +349 -0
  23. data/features/create_slide-cli.feature +188 -0
  24. data/features/create_slides-templates-cli.feature +114 -0
  25. data/features/create_theme-cli.feature +58 -0
  26. data/features/default_slides.feature +58 -0
  27. data/features/edit_slide-cli.feature +121 -0
  28. data/features/export_presentation-cli.feature +23 -0
  29. data/features/grouping_slides.feature +150 -0
  30. data/features/ignore_slides.feature +103 -0
  31. data/features/init_application-cli.feature +59 -0
  32. data/features/init_predefined_slides.feature +9 -0
  33. data/features/language_detection.feature +0 -0
  34. data/features/list_assets-cli.feature +13 -0
  35. data/features/list_components-cli.feature +13 -0
  36. data/features/list_helpers-cli.feature +13 -0
  37. data/features/list_plugins-cli.feature +13 -0
  38. data/features/list_styles-cli.feature +17 -0
  39. data/features/plugins.feature +63 -0
  40. data/features/presentation.feature +57 -0
  41. data/features/rename_slide-cli.feature +176 -0
  42. data/features/render_slides.feature +76 -0
  43. data/features/show_config-cli.feature +25 -0
  44. data/features/show_footer.feature +14 -0
  45. data/features/show_slide_number.feature +31 -0
  46. data/features/show_support_information-cli.feature +12 -0
  47. data/features/support/aruba.rb +18 -0
  48. data/features/support/ci.rb +3 -0
  49. data/features/support/env.rb +25 -0
  50. data/features/support/fixtures.rb +21 -0
  51. data/features/support/hash.rb +2 -0
  52. data/features/support/reporting.rb +2 -0
  53. data/features/version_number.feature +15 -0
  54. data/fixtures/middleman-presentation-simple_plugin/Rakefile +1 -0
  55. data/fixtures/middleman-presentation-simple_plugin/lib/middleman-presentation-plugin.rb +0 -0
  56. data/fixtures/middleman-presentation-simple_plugin/lib/middleman-presentation-simple_plugin/helpers.rb +13 -0
  57. data/fixtures/middleman-presentation-simple_plugin/lib/middleman-presentation-simple_plugin/plugin.rb +34 -0
  58. data/fixtures/middleman-presentation-simple_plugin/lib/middleman-presentation-simple_plugin/version.rb +8 -0
  59. data/fixtures/middleman-presentation-simple_plugin/lib/middleman-presentation-simple_plugin.rb +11 -0
  60. data/fixtures/middleman-presentation-simple_plugin/middleman-presentation-simple_plugin.gemspec +22 -0
  61. data/fixtures/middleman-presentation-simple_plugin/vendor/assets/stylesheets/test_simple.scss +3 -0
  62. data/lib/middleman-presentation-core/application_config.rb +198 -0
  63. data/lib/middleman-presentation-core/asset.rb +103 -0
  64. data/lib/middleman-presentation-core/asset_component.rb +34 -0
  65. data/lib/middleman-presentation-core/asset_list.rb +84 -0
  66. data/lib/middleman-presentation-core/asset_store.rb +73 -0
  67. data/lib/middleman-presentation-core/assets_loader.rb +95 -0
  68. data/lib/middleman-presentation-core/assets_manager.rb +73 -0
  69. data/lib/middleman-presentation-core/cache.rb +49 -0
  70. data/lib/middleman-presentation-core/cli/base.rb +30 -0
  71. data/lib/middleman-presentation-core/cli/base_group.rb +11 -0
  72. data/lib/middleman-presentation-core/cli/build.rb +13 -0
  73. data/lib/middleman-presentation-core/cli/build_presentation.rb +57 -0
  74. data/lib/middleman-presentation-core/cli/change.rb +13 -0
  75. data/lib/middleman-presentation-core/cli/change_slide.rb +82 -0
  76. data/lib/middleman-presentation-core/cli/create.rb +16 -0
  77. data/lib/middleman-presentation-core/cli/create_plugin.rb +62 -0
  78. data/lib/middleman-presentation-core/cli/create_presentation.rb +300 -0
  79. data/lib/middleman-presentation-core/cli/create_slide.rb +52 -0
  80. data/lib/middleman-presentation-core/cli/create_theme.rb +81 -0
  81. data/lib/middleman-presentation-core/cli/edit.rb +13 -0
  82. data/lib/middleman-presentation-core/cli/edit_slide.rb +49 -0
  83. data/lib/middleman-presentation-core/cli/export.rb +11 -0
  84. data/lib/middleman-presentation-core/cli/export_presentation.rb +55 -0
  85. data/lib/middleman-presentation-core/cli/init.rb +12 -0
  86. data/lib/middleman-presentation-core/cli/init_application.rb +48 -0
  87. data/lib/middleman-presentation-core/cli/init_predefined_slides.rb +31 -0
  88. data/lib/middleman-presentation-core/cli/list.rb +66 -0
  89. data/lib/middleman-presentation-core/cli/reset_thor.rb +18 -0
  90. data/lib/middleman-presentation-core/cli/runner.rb +47 -0
  91. data/lib/middleman-presentation-core/cli/serve.rb +13 -0
  92. data/lib/middleman-presentation-core/cli/serve_presentation.rb +30 -0
  93. data/lib/middleman-presentation-core/cli/shared.rb +51 -0
  94. data/lib/middleman-presentation-core/cli/show.rb +70 -0
  95. data/lib/middleman-presentation-core/comparable_slide.rb +69 -0
  96. data/lib/middleman-presentation-core/component.rb +86 -0
  97. data/lib/middleman-presentation-core/components_manager.rb +96 -0
  98. data/lib/middleman-presentation-core/configuration_file.rb +15 -0
  99. data/lib/middleman-presentation-core/css_class_extracter.rb +41 -0
  100. data/lib/middleman-presentation-core/custom_template.rb +15 -0
  101. data/lib/middleman-presentation-core/erb_template.rb +15 -0
  102. data/lib/middleman-presentation-core/errors.rb +10 -0
  103. data/lib/middleman-presentation-core/existing_slide.rb +92 -0
  104. data/lib/middleman-presentation-core/frontend_component.rb +75 -0
  105. data/lib/middleman-presentation-core/group_template.rb +15 -0
  106. data/lib/middleman-presentation-core/helpers_manager.rb +37 -0
  107. data/lib/middleman-presentation-core/ignore_file.rb +52 -0
  108. data/lib/middleman-presentation-core/liquid_template.rb +15 -0
  109. data/lib/middleman-presentation-core/list.rb +7 -0
  110. data/lib/middleman-presentation-core/locale_configurator.rb +84 -0
  111. data/lib/middleman-presentation-core/logger.rb +8 -0
  112. data/lib/middleman-presentation-core/main.rb +55 -0
  113. data/lib/middleman-presentation-core/markdown_template.rb +15 -0
  114. data/lib/middleman-presentation-core/middleman_environment.rb +108 -0
  115. data/lib/middleman-presentation-core/middleman_extension.rb +12 -0
  116. data/lib/middleman-presentation-core/middleman_step_definitions.rb +131 -0
  117. data/lib/middleman-presentation-core/new_slide.rb +140 -0
  118. data/lib/middleman-presentation-core/overwrite_sass.rb +22 -0
  119. data/lib/middleman-presentation-core/plugin.rb +8 -0
  120. data/lib/middleman-presentation-core/plugin_api.rb +65 -0
  121. data/lib/middleman-presentation-core/plugins_manager.rb +7 -0
  122. data/lib/middleman-presentation-core/predefined_slide_templates_directory.rb +15 -0
  123. data/lib/middleman-presentation-core/presentation_helper.rb +69 -0
  124. data/lib/middleman-presentation-core/register_extension.rb +4 -0
  125. data/lib/middleman-presentation-core/roles/comparable_by_name.rb +24 -0
  126. data/lib/middleman-presentation-core/slide_group.rb +33 -0
  127. data/lib/middleman-presentation-core/slide_list.rb +52 -0
  128. data/lib/middleman-presentation-core/slide_name.rb +61 -0
  129. data/lib/middleman-presentation-core/start.rb +68 -0
  130. data/lib/middleman-presentation-core/step_definitions.rb +238 -0
  131. data/lib/middleman-presentation-core/syntax_highlighter.rb +42 -0
  132. data/lib/middleman-presentation-core/test_helpers.rb +22 -0
  133. data/lib/middleman-presentation-core/transformers/file_keeper.rb +13 -0
  134. data/lib/middleman-presentation-core/transformers/group_slides.rb +34 -0
  135. data/lib/middleman-presentation-core/transformers/ignore_slides.rb +28 -0
  136. data/lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb +32 -0
  137. data/lib/middleman-presentation-core/transformers/sort_slides.rb +13 -0
  138. data/lib/middleman-presentation-core/utils.rb +40 -0
  139. data/lib/middleman-presentation-core/version.rb +8 -0
  140. data/lib/middleman-presentation-core.rb +127 -0
  141. data/locales/de.yml +233 -0
  142. data/locales/en.yml +236 -0
  143. data/middleman-presentation-core.gemspec +40 -0
  144. data/source/slides/01.html.liquid +0 -0
  145. data/spec/asset_component_spec.rb +13 -0
  146. data/spec/asset_list_spec.rb +50 -0
  147. data/spec/asset_spec.rb +45 -0
  148. data/spec/asset_store_spec.rb +61 -0
  149. data/spec/assets_manager_spec.rb +111 -0
  150. data/spec/components_manager_spec.rb +142 -0
  151. data/spec/css_class_extracter_spec.rb +28 -0
  152. data/spec/existing_slide_spec.rb +177 -0
  153. data/spec/frontend_component_spec.rb +94 -0
  154. data/spec/helpers_manager_spec.rb +90 -0
  155. data/spec/ignore_file_spec.rb +75 -0
  156. data/spec/new_slide_spec.rb +155 -0
  157. data/spec/presentation_helper_spec.rb +137 -0
  158. data/spec/shared_examples/.keep +0 -0
  159. data/spec/slide_group_spec.rb +54 -0
  160. data/spec/slide_list_spec.rb +125 -0
  161. data/spec/slide_name_spec.rb +53 -0
  162. data/spec/spec_helper.rb +19 -0
  163. data/spec/support/aruba.rb +53 -0
  164. data/spec/support/ci.rb +20 -0
  165. data/spec/support/environment.rb +18 -0
  166. data/spec/support/filesystem.rb +22 -0
  167. data/spec/support/locale.rb +2 -0
  168. data/spec/support/reporting.rb +2 -0
  169. data/spec/support/rspec.rb +9 -0
  170. data/spec/support/string.rb +2 -0
  171. data/spec/transformers/file_keeper_spec.rb +24 -0
  172. data/spec/transformers/group_slides_spec.rb +44 -0
  173. data/spec/transformers/ignore_slides_spec.rb +64 -0
  174. data/spec/transformers/remove_duplicate_slides_spec.rb +120 -0
  175. data/spec/transformers/sort_slides_spec.rb +17 -0
  176. data/spec/utils_spec.rb +14 -0
  177. data/templates/.bowerrc.tt +4 -0
  178. data/templates/.gitignore +5 -0
  179. data/templates/Gemfile.tt +32 -0
  180. data/templates/LICENSE.presentation +1 -0
  181. data/templates/Rakefile +59 -0
  182. data/templates/bower.json.tt +8 -0
  183. data/templates/bundler_config.tt +6 -0
  184. data/templates/config.rb.tt +2 -0
  185. data/templates/config.yaml.tt +17 -0
  186. data/templates/gitignore.tt +14 -0
  187. data/templates/plugin/%plugin_name%.gemspec.tt +24 -0
  188. data/templates/plugin/.gitignore +13 -0
  189. data/templates/plugin/Gemfile.tt +4 -0
  190. data/templates/plugin/LICENSE.txt.tt +22 -0
  191. data/templates/plugin/README.md.tt +31 -0
  192. data/templates/plugin/Rakefile +1 -0
  193. data/templates/plugin/lib/%plugin_name%/version.rb.tt +8 -0
  194. data/templates/plugin/lib/%plugin_name%.rb.tt +10 -0
  195. data/templates/predefined_slides.d/00_00.html.erb.tt +26 -0
  196. data/templates/predefined_slides.d/00_01.html.md.tt +6 -0
  197. data/templates/predefined_slides.d/999980.html.erb.tt +4 -0
  198. data/templates/predefined_slides.d/999981.html.erb.tt +27 -0
  199. data/templates/predefined_slides.d/999982.html.erb.tt +4 -0
  200. data/templates/presentation_theme/bower.json.tt +20 -0
  201. data/templates/presentation_theme/images/.keep +0 -0
  202. data/templates/presentation_theme/javascripts/%theme_name%.js.tt +0 -0
  203. data/templates/presentation_theme/stylesheets/%theme_name%.scss.tt +9 -0
  204. data/templates/presentation_theme/stylesheets/_fonts.scss.tt +0 -0
  205. data/templates/presentation_theme/stylesheets/_images.scss.tt +5 -0
  206. data/templates/presentation_theme/stylesheets/_theme.scss.tt +251 -0
  207. data/templates/rackup.config.erb +16 -0
  208. data/templates/script/bootstrap +5 -0
  209. data/templates/script/build +3 -0
  210. data/templates/script/export +3 -0
  211. data/templates/script/presentation +3 -0
  212. data/templates/script/slide +3 -0
  213. data/templates/script/start +43 -0
  214. data/templates/slides/custom.md.tt +3 -0
  215. data/templates/slides/erb.tt +5 -0
  216. data/templates/slides/group.tt +3 -0
  217. data/templates/slides/liquid.tt +5 -0
  218. data/templates/slides/markdown.tt +3 -0
  219. data/templates/source/index.html.erb +1 -0
  220. data/templates/source/javascripts/application.js.tt +3 -0
  221. data/templates/source/layout.erb +133 -0
  222. data/templates/source/stylesheets/application.scss.tt +3 -0
  223. metadata +574 -0
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # A component
5
+ class Component
6
+ include Comparable
7
+
8
+ attr_reader :name, :resource_locator, :version, :importable_files, :loadable_files, :ignorable_files, :output_paths
9
+
10
+ # Create new component
11
+ #
12
+ # @param [String] resource_locator
13
+ # The locator to look for the resource, e.g. http://example.org/test or latest
14
+ #
15
+ # @param [String] name (nil)
16
+ # Alternative name for the resource, otherwise the base name of the resource_locator's path is used: http://example.org/test => test
17
+ #
18
+ # @param [String] github
19
+ # Name of github repository, e.g. <account>/<repository>
20
+ # rubocop:disable Metrics/ParameterLists
21
+ def initialize(
22
+ resource_locator: nil,
23
+ version: nil,
24
+ name: nil,
25
+ github: nil,
26
+ importable_files: [],
27
+ loadable_files: [],
28
+ ignorable_files: [],
29
+ output_paths: []
30
+ )
31
+
32
+ @name = name
33
+ @resource_locator = resource_locator
34
+ @version = version
35
+ @github = github
36
+ @loadable_files = Array(loadable_files).map { |o| Regexp.new o }
37
+ @importable_files = Array(importable_files).map { |o| Regexp.new o }
38
+ @ignorable_files = Array(ignorable_files).map { |o| Regexp.new o }
39
+ @output_paths = Array(output_paths)
40
+ end
41
+ # rubocop:enable Metrics/ParameterLists
42
+
43
+ # Return path to component
44
+ #
45
+ # If root directory is set, it will be prepended to name.
46
+ def path
47
+ fail NoMethodError, :path
48
+ end
49
+
50
+ # Base path for component
51
+ #
52
+ # The path where the component can be found.
53
+ def base_path
54
+ fail NoMethodError, :base_path
55
+ end
56
+
57
+ # Configure accessor for root directory
58
+ def root_directory
59
+ fail NoMethodError, :root_directory
60
+ end
61
+
62
+ # Configure accessor for root directory
63
+ def root_directory=(*)
64
+ fail NoMethodError, :root_directory=
65
+ end
66
+
67
+ # Should middleman-presentation fetch the component
68
+ def fetchable?
69
+ false
70
+ end
71
+
72
+ # Return resource locator
73
+ #
74
+ # @return [String]
75
+ # The resource locator
76
+ def resource_locator
77
+ @resource_locator.to_s
78
+ end
79
+
80
+ # @private
81
+ def <=>(other)
82
+ name.to_s <=> other.name.to_s
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Component Manager
5
+ #
6
+ # It know about all frontend components. Information about all frontend
7
+ # components is used when building `application.js` and `application.scss`
8
+ # during website build and when creating the `bower.json`-file on
9
+ # presentation-creation.
10
+ #
11
+ # It normally gets the information about available components from
12
+ # `plugins`.
13
+ class ComponentsManager
14
+ private
15
+
16
+ attr_reader :bower_directory, :cache
17
+
18
+ public
19
+
20
+ def initialize(cache: Cache.new(store: Set.new))
21
+ @cache = cache
22
+ @bower_directory = nil
23
+ end
24
+
25
+ # Return available frontend components
26
+ def available_components
27
+ components.to_a
28
+ end
29
+
30
+ def bower_directory=(value)
31
+ @bower_directory = value
32
+ cache.mark_dirty
33
+ end
34
+
35
+ # Return components
36
+ #
37
+ # Will used cached results until a new component is added
38
+ def components
39
+ cache.each { |c| c.root_directory = bower_directory }
40
+
41
+ cache.to_a
42
+ end
43
+
44
+ # Iterate over all fetchable components
45
+ def each_fetchable_component(&block)
46
+ components = self.components.select(&:fetchable?)
47
+
48
+ return components.each unless block_given?
49
+
50
+ components.each do |c|
51
+ block.call(c, c.equal?(components.last))
52
+ end
53
+ end
54
+
55
+ # Iterate over all fetchable components
56
+ def each_nonfetchable_component(&block)
57
+ components = self.components.select { |c| !c.fetchable? }
58
+
59
+ return components.each unless block_given?
60
+
61
+ components.each do |c|
62
+ block.call(c, c.equal?(components.last))
63
+ end
64
+ end
65
+
66
+ # Add component
67
+ def add(c)
68
+ unless c.respond_to? :root_directory=
69
+ Middleman::Presentation.logger.error Middleman::Presentation.t('errors.invalid_component', argument: c)
70
+ return
71
+ end
72
+
73
+ cache.add c
74
+ end
75
+
76
+ # List installed plugins
77
+ def to_s
78
+ data = components.sort.reduce([]) do |a, e|
79
+ a << {
80
+ name: e.name,
81
+ path: e.path,
82
+ base_path: e.base_path,
83
+ resource_locator: e.resource_locator,
84
+ version: e.version,
85
+ loadable_files: e.loadable_files,
86
+ importable_files: e.importable_files,
87
+ ignorable_files: e.ignorable_files,
88
+ output_paths: e.output_paths
89
+ }
90
+ end
91
+
92
+ List.new(data).to_s(fields: [:name, :path, :base_path, :resource_locator, :version, :importable_files, :loadable_files, :ignorable_files, :output_paths], vertical: true)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Find the config.rb of middleman
5
+ class ConfigurationFile
6
+ extend Forwardable
7
+
8
+ def_delegators :@file_finder, :directory, :file
9
+
10
+ def initialize(raise_error: true)
11
+ @file_finder = FeduxOrgStdlib::RecursiveFileFinder.new(file_name: 'config.rb', raise_error: raise_error)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Extract css classes from html files
5
+ class CssClassExtracter
6
+ # Extracted css class
7
+ class CssClass
8
+ attr_reader :name, :files
9
+
10
+ def initialize(name:, files: [])
11
+ @name = name
12
+ @files = files.to_a
13
+ end
14
+ end
15
+
16
+ def extract(paths, ignore: [])
17
+ classes = build(paths)
18
+ classes.delete_if { |klass| ignore.include? klass }.sort_by { |klass, _| klass }.map { |klass, files| CssClass.new(name: klass, files: files) }
19
+ end
20
+
21
+ private
22
+
23
+ def build(paths)
24
+ paths.each_with_object({}) do |f, a|
25
+ page = Nokogiri::HTML(open(f))
26
+
27
+ page.traverse do |n|
28
+ if n['class']
29
+ klasses = n['class'].split(/ /)
30
+
31
+ klasses.each do |k|
32
+ a[k] ||= Set.new
33
+ a[k] << File.basename(f)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Custom template for a new slide
5
+ class CustomTemplate < FeduxOrgStdlib::FileTemplate
6
+ def application_name
7
+ 'middleman-presentation'
8
+ end
9
+
10
+ def fallback_template_directory
11
+ File.expand_path('../../../templates/slides', __FILE__)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Erb template for a new slide
5
+ class ErbTemplate < FeduxOrgStdlib::FileTemplate
6
+ def application_name
7
+ 'middleman-presentation'
8
+ end
9
+
10
+ def fallback_template_directory
11
+ File.expand_path('../../../templates/slides', __FILE__)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # if fixture cannot be found by name
5
+ class FixtureNotFoundError < StandardError; end
6
+
7
+ # if plugin cannot be found by name
8
+ class PluginNotFoundError < StandardError; end
9
+ end
10
+ end
@@ -0,0 +1,92 @@
1
+ # encoding
2
+ module Middleman
3
+ module Presentation
4
+ # Used for slides which already exist in file system
5
+ class ExistingSlide
6
+ include ComparableSlide
7
+
8
+ attr_reader :path
9
+
10
+ private
11
+
12
+ attr_reader :base_path
13
+
14
+ public
15
+
16
+ # Create Existin slide object
17
+ def initialize(path, base_path: nil)
18
+ @path = Pathname.new(path)
19
+
20
+ base_path = @path.dirname if base_path.blank?
21
+ @base_path = Pathname.new(base_path)
22
+ end
23
+
24
+ # Relative path inside source directory
25
+ def relative_path
26
+ path.relative_path_from(base_path)
27
+ end
28
+
29
+ # Group of slide
30
+ def group
31
+ @group ||= extract_group
32
+ end
33
+
34
+ # Filename of slide, e.g 01.html.erb
35
+ def file_name
36
+ path.basename
37
+ end
38
+
39
+ # Does slide really exist in filesystem
40
+ def exist?
41
+ path.exist?
42
+ end
43
+
44
+ # Render slide
45
+ def render(&block)
46
+ result = []
47
+ result << "<!-- #{relative_path} -->"
48
+ result << block.call(path).to_s
49
+
50
+ result.join("\n")
51
+ end
52
+
53
+ # String representation of slide
54
+ def to_s
55
+ path.to_s
56
+ end
57
+
58
+ # Return partial path of existing slide
59
+ def partial_path
60
+ dirname, base = relative_path.split
61
+
62
+ base = base.basename('.*') until base.extname.blank?
63
+
64
+ dirname + base
65
+ end
66
+
67
+ # Return base name for slide
68
+ def base_name
69
+ base = relative_path.basename
70
+
71
+ base = base.basename('.*') until base.extname.blank?
72
+
73
+ base.to_s
74
+ end
75
+
76
+ # Return ext name for slide
77
+ def ext_name
78
+ file_name.to_s.gsub(/^([^.]+)\./, '.')
79
+ end
80
+
81
+ private
82
+
83
+ def extract_group
84
+ group = relative_path.dirname.basename
85
+
86
+ return nil if group == relative_path.dirname
87
+
88
+ group.to_s
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # A frontend component
5
+ #
6
+ # It represents a bower component. A bower component can contain
7
+ # JavaScript-files, stylesheets, images, fonts, ... . A frontend component
8
+ # know where to get a bower component from, which version of the component
9
+ # is required and which JavaScript-files and stylesheets should be includes
10
+ # in "javascripts/application.js" and "stylesheets"application.scss".
11
+ class FrontendComponent < Component
12
+ attr_accessor :root_directory
13
+
14
+ # Create new frontend component
15
+ #
16
+ # @see [Component] For all other params
17
+ #
18
+ # @param [String] root_directory
19
+ # The directory where all frontend components can be found
20
+ def initialize(**args)
21
+ super(**args)
22
+
23
+ @resource_locator = if @resource_locator =~ /\A#{URI.regexp}\z/
24
+ Addressable::URI.heuristic_parse @resource_locator
25
+ elsif @github
26
+ Addressable::URI.heuristic_parse format('https://github.com/%s.git', @github)
27
+ elsif version
28
+ Class.new do
29
+ attr_reader :to_s
30
+
31
+ def initialize(value)
32
+ @to_s = value
33
+ end
34
+ end.new(version)
35
+ else
36
+ nil
37
+ end
38
+ fail ArgumentError, Middleman::Presentation.t('errors.undefined_arguments', arguments: %w(resource_locator github version).to_list) if @resource_locator.blank?
39
+
40
+ @name = if version
41
+ name
42
+ elsif name.blank?
43
+ File.basename(@resource_locator.path)
44
+ else
45
+ name
46
+ end
47
+
48
+ fail ArgumentError, Middleman::Presentation.t('errors.argument_error', argument: :name, value: @name) if @name.blank?
49
+
50
+ @root_directory = root_directory
51
+ end
52
+
53
+ # Return path to component
54
+ #
55
+ # If root directory is set, it will be prepended to name.
56
+ def path
57
+ args = []
58
+ args << root_directory if root_directory
59
+ args << name.to_s
60
+
61
+ Pathname.new(File.join(*args))
62
+ end
63
+
64
+ # Base path for component
65
+ def base_path
66
+ path.dirname
67
+ end
68
+
69
+ # Should middleman-presentation fetch the component
70
+ def fetchable?
71
+ true
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Template for a group of slides
5
+ class GroupTemplate < FeduxOrgStdlib::FileTemplate
6
+ def application_name
7
+ 'middleman-presentation'
8
+ end
9
+
10
+ def fallback_template_directory
11
+ File.expand_path('../../../templates/slides', __FILE__)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Manager for helper modules
5
+ class HelpersManager
6
+ private
7
+
8
+ attr_reader :presentation_helpers
9
+
10
+ public
11
+
12
+ def initialize(_creator: PresentationHelper)
13
+ @presentation_helpers = []
14
+ end
15
+
16
+ # Add helpers
17
+ def add(*modules, &block)
18
+ presentation_helpers.concat PresentationHelper.parse(modules)
19
+ presentation_helpers << PresentationHelper.new(block) if block_given?
20
+ end
21
+
22
+ # Return available helpers
23
+ def available_helpers
24
+ presentation_helpers.reduce(Module.new) { |a, e| a.include e.to_module }
25
+ end
26
+
27
+ # Show helper modules
28
+ def to_s
29
+ data = presentation_helpers.sort.reduce([]) do |a, e|
30
+ a << { name: e.name, type: e.type, available_methods: e.available_methods.to_list }
31
+ end
32
+
33
+ List.new(data).to_s(fields: [:name, :type, :available_methods])
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # The ignore file uses to ignore slides
5
+ #
6
+ # @see [Transformers::IgnoreSlides]
7
+ class IgnoreFile
8
+ private
9
+
10
+ attr_reader :unignore, :ignore, :path
11
+
12
+ protected
13
+
14
+ attr_writer :unignore, :ignore
15
+
16
+ public
17
+
18
+ def initialize(path)
19
+ @unignore = @ignore = /^!$/
20
+ @path = path
21
+
22
+ parse_file(path) if File.exist? path
23
+ end
24
+
25
+ def ignore?(slide)
26
+ return false unless File.exist? path
27
+
28
+ slide.match?(ignore) && !slide.match?(unignore)
29
+ end
30
+
31
+ private
32
+
33
+ def parse_file(path)
34
+ File.readlines(path).each do |l|
35
+ next if l =~ /^#/
36
+ l = l.chomp.sub(/\s*#.*/, '')
37
+
38
+ if l =~ /^!/
39
+ self.unignore = Regexp.union(
40
+ unignore,
41
+ Regexp.new(
42
+ l.sub(/^!/, '')
43
+ )
44
+ )
45
+ else
46
+ self.ignore = Regexp.union(ignore, Regexp.new(l))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Liquid template for creating slides
5
+ class LiquidTemplate < FeduxOrgStdlib::FileTemplate
6
+ def application_name
7
+ 'middleman-presentation'
8
+ end
9
+
10
+ def fallback_template_directory
11
+ File.expand_path('../../../templates/slides', __FILE__)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ class List < FeduxOrgStdlib::List
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Configuration for language on cli
5
+ class LocaleConfigurator
6
+ private
7
+
8
+ attr_reader :pattern, :detector, :detected_locale, :logger
9
+
10
+ public
11
+
12
+ def initialize(
13
+ path:,
14
+ default_locale: nil,
15
+ enforce_available_locales: true,
16
+ detector: FeduxOrgStdlib::ShellLanguageDetector.new,
17
+ logger: FeduxOrgStdlib::Logging::Logger.new
18
+ )
19
+ @pattern = File.join(path, '*.yml')
20
+ @detector = detector
21
+ @detected_locale = detect_locale(overwrite: default_locale)
22
+ @logger = logger
23
+
24
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
25
+ I18n.load_path = locale_files
26
+ I18n.backend.load_translations
27
+
28
+ I18n.default_locale = @detected_locale
29
+ I18n.available_locales = available_locales
30
+ I18n.enforce_available_locales = enforce_available_locales
31
+ end
32
+
33
+ def use_locale(l)
34
+ l = l.to_sym
35
+
36
+ if l.blank?
37
+ logger.warn I18n.t('errors.use_empty_locale', codes: available_locales.to_list, fallback_locale: detected_locale)
38
+ return
39
+ end
40
+
41
+ unless valid_locale?(l)
42
+ logger.warn I18n.t('errors.use_invalid_locale', codes: available_locales.to_list, fallback_locale: detected_locale)
43
+ return
44
+ end
45
+
46
+ I18n.locale = l
47
+ end
48
+
49
+ def available_locales
50
+ locale_files.map { |f| File.basename(f, '.yml').to_sym }
51
+ end
52
+
53
+ def t(*args, &block)
54
+ I18n.t(*args, &block)
55
+ end
56
+
57
+ def validate_and_return_locale(l)
58
+ return l.to_sym if valid_locale? l
59
+
60
+ logger.warn I18n.t('errors.use_invalid_locale', codes: available_locales.to_list, fallback_locale: detected_locale)
61
+
62
+ detected_locale
63
+ end
64
+
65
+ private
66
+
67
+ def valid_locale?(l)
68
+ available_locales.include? l.to_sym
69
+ end
70
+
71
+ def detect_locale(overwrite:)
72
+ options = {}
73
+ options[:allowed] = available_locales
74
+ options[:overwrite] = overwrite.to_sym if overwrite
75
+
76
+ detector.detect(**options).language_code
77
+ end
78
+
79
+ def locale_files
80
+ @locale_files ||= Dir.glob(pattern)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Presentation
4
+ # Logger
5
+ class Logger < FeduxOrgStdlib::Logging::Logger
6
+ end
7
+ end
8
+ end