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,94 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe FrontendComponent do
5
+ context '#initialize' do
6
+ it 'supports a full url as resource locator' do
7
+ expect do
8
+ FrontendComponent.new(resource_locator: 'http://www.example.org/test')
9
+ end.not_to raise_error
10
+ end
11
+
12
+ it 'fails if neither github nor resource_locator is given' do
13
+ expect do
14
+ FrontendComponent.new
15
+ end.to raise_error ArgumentError
16
+ end
17
+
18
+ it 'build github url' do
19
+ expect do
20
+ FrontendComponent.new(github: 'example/example')
21
+ end.not_to raise_error
22
+ end
23
+
24
+ it 'fails if name is empty when extracted from url' do
25
+ expect do
26
+ FrontendComponent.new(resource_locator: 'http://www.example.org')
27
+ end.to raise_error ArgumentError
28
+ end
29
+
30
+ it 'requires name if version is given' do
31
+ expect do
32
+ FrontendComponent.new(version: '1.1.1', name: 'blub')
33
+ end.not_to raise_error
34
+ end
35
+
36
+ it 'fails if version is given but no name' do
37
+ expect do
38
+ FrontendComponent.new(version: '1.1.1')
39
+ end.to raise_error ArgumentError
40
+ end
41
+ end
42
+
43
+ context '#name' do
44
+ it 'extracts name from url' do
45
+ component = FrontendComponent.new(resource_locator: 'http://example.org/test')
46
+ expect(component.name).to eq 'test'
47
+ end
48
+
49
+ it 'uses name' do
50
+ component = FrontendComponent.new(resource_locator: 'http://example.org/test', name: 'name')
51
+ expect(component.name).to eq 'name'
52
+ end
53
+ end
54
+
55
+ context '#resource_locator' do
56
+ it 'uses version as resource_locator' do
57
+ component = FrontendComponent.new(name: 'asdf', version: '0.0.1')
58
+ expect(component.resource_locator).to eq '0.0.1'
59
+ end
60
+
61
+ it 'uses url as resource_locator' do
62
+ component = FrontendComponent.new(resource_locator: 'http://example.org/test')
63
+ expect(component.resource_locator).to eq 'http://example.org/test'
64
+ end
65
+
66
+ it 'uses github repository as resource_locator' do
67
+ component = FrontendComponent.new(github: 'example.org/test')
68
+ expect(component.resource_locator).to eq 'https://github.com/example.org/test.git'
69
+ end
70
+ end
71
+
72
+ context '#path' do
73
+ it 'is root directory + name' do
74
+ root_directory = absolute_path('test.d')
75
+ name = 'test'
76
+
77
+ component = FrontendComponent.new(name: name, version: 'latest')
78
+ component.root_directory = root_directory
79
+
80
+ expect(component.path).to eq Pathname.new(File.join(root_directory, name))
81
+ end
82
+ end
83
+
84
+ context '#base_path' do
85
+ it 'returns the path of frontend component without name' do
86
+ root_directory = absolute_path('test.d')
87
+
88
+ component = FrontendComponent.new(name: 'test', version: 'latest')
89
+ component.root_directory = root_directory
90
+
91
+ expect(component.base_path).to eq Pathname.new(root_directory)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe HelpersManager do
5
+ let(:helpers_module) do
6
+ Module.new do
7
+ def helper1
8
+ 'helper1'
9
+ end
10
+ end
11
+ end
12
+
13
+ context '#add' do
14
+ it 'let you add modules' do
15
+ stub_const('HelpersModule', helpers_module)
16
+
17
+ manager = HelpersManager.new
18
+ manager.add HelpersModule
19
+ end
20
+
21
+ it 'let you add procs' do
22
+ manager = HelpersManager.new
23
+ manager.add do
24
+ def helper1
25
+ 'helper1'
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ context '#available_helpers' do
32
+ it 'returns a module' do
33
+ manager = HelpersManager.new
34
+ manager.add do
35
+ def helper1
36
+ 'helper1'
37
+ end
38
+ end
39
+
40
+ expect(manager.available_helpers).to be_kind_of Module
41
+ end
42
+
43
+ it 'the returned module has all methods in there' do
44
+ manager = HelpersManager.new
45
+ manager.add do
46
+ def helper1
47
+ 'helper1'
48
+ end
49
+ end
50
+
51
+ local_module = Module.new do
52
+ extend manager.available_helpers
53
+ end
54
+
55
+ expect(local_module.helper1).to eq 'helper1'
56
+ end
57
+ end
58
+
59
+ context '#to_s' do
60
+ it 'returns a string representation of self' do
61
+ stub_const('HelpersModule', helpers_module)
62
+
63
+ manager = HelpersManager.new
64
+ manager.add HelpersModule
65
+ manager.add do
66
+ def helper2
67
+ 'helper2'
68
+ end
69
+
70
+ def helper3
71
+ 'helper3'
72
+ end
73
+
74
+ def self.helper4
75
+ 'helper4'
76
+ end
77
+ end
78
+
79
+ expect(manager.to_s).to eq <<-EOS.strip_heredoc.chomp
80
+ +---------------+--------+--------------------------------------+
81
+ | Name | Type | Available methods |
82
+ +---------------+--------+--------------------------------------+
83
+ | <Anonymous> | PROC | "helper2", "helper3", "self.helper4" |
84
+ | HelpersModule | MODULE | "helper1" |
85
+ +---------------+--------+--------------------------------------+
86
+ 2 rows in set
87
+ EOS
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe IgnoreFile do
5
+ context '#initialize' do
6
+ it 'succeeds if path is given' do
7
+ expect do
8
+ file = touch_file('ignore_file')
9
+ IgnoreFile.new absolute_path(file)
10
+ end.not_to raise_error
11
+ end
12
+
13
+ it 'fails if path is missing' do
14
+ expect do
15
+ IgnoreFile.new
16
+ end.to raise_error ArgumentError
17
+ end
18
+
19
+ context '#ignore?' do
20
+ it 'checks if slide can be ignored' do
21
+ slide1 = instance_double('Middleman::Presentation::ExistingSlide')
22
+ allow(slide1).to receive(:match?).and_return(false)
23
+ allow(slide1).to receive(:match?).with(/(?-mix:^!$)|(?-mix:01)/).and_return(true)
24
+
25
+ slide2 = instance_double('Middleman::Presentation::ExistingSlide')
26
+ allow(slide2).to receive(:match?).and_return(false)
27
+
28
+ file = write_file 'ignore_file', <<-EOS.strip_heredoc
29
+ 01
30
+ EOS
31
+
32
+ ignore_file = IgnoreFile.new(absolute_path(file))
33
+
34
+ expect(ignore_file).to be_ignore slide1
35
+ expect(ignore_file).not_to be_ignore slide2
36
+ end
37
+
38
+ it 'strips off full line comments' do
39
+ slide1 = instance_double('Middleman::Presentation::ExistingSlide')
40
+ allow(slide1).to receive(:match?).with(/(?-mix:^!$)|(?-mix:02)/).and_return(false)
41
+
42
+ path = write_file 'ignore_file', <<-EOS.strip_heredoc
43
+ # 01
44
+ 02
45
+ EOS
46
+
47
+ file = IgnoreFile.new(path)
48
+
49
+ expect(file).not_to be_ignore slide1
50
+ end
51
+
52
+ it 'strips off line comments' do
53
+ slide1 = instance_double('Middleman::Presentation::ExistingSlide')
54
+ allow(slide1).to receive(:match?).and_return(false)
55
+ allow(slide1).to receive(:match?).with(/(?-mix:^!$)|(?-mix:01)/).and_return(true)
56
+
57
+ file = write_file 'ignore_file', <<-EOS.strip_heredoc
58
+ 01 # hello world
59
+ EOS
60
+
61
+ ignore_file = IgnoreFile.new(absolute_path(file))
62
+
63
+ expect(ignore_file).to be_ignore slide1
64
+ end
65
+
66
+ it 'handles non existing ignore file' do
67
+ slide1 = instance_double('Middleman::Presentation::ExistingSlide')
68
+
69
+ file = IgnoreFile.new SecureRandom.hex
70
+
71
+ expect(file).not_to be_ignore slide1
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,155 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe NewSlide do
5
+
6
+ context '#<=>' do
7
+ it 'compares slides with same file name' do
8
+ slide1 = NewSlide.new('01.md', base_path: absolute_path('source', 'slides'))
9
+ slide2 = NewSlide.new('01.md', base_path: absolute_path('source', 'slides'))
10
+
11
+ expect(slide1).to eq slide2
12
+ end
13
+
14
+ it 'compares slides with different file names' do
15
+ slide1 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
16
+ slide2 = NewSlide.new('01.md', base_path: absolute_path('source', 'slides'))
17
+
18
+ expect(slide1).not_to eq slide2
19
+ end
20
+
21
+ it 'compares slides with not extension at all' do
22
+ slide1 = NewSlide.new('01', base_path: absolute_path('source', 'slides'))
23
+ slide2 = NewSlide.new('01', base_path: absolute_path('source', 'slides'))
24
+
25
+ expect(slide1).to eq slide2
26
+ end
27
+ end
28
+
29
+ context '#eql?' do
30
+ it 'succeeds on eqal file names' do
31
+ slide1 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
32
+ slide2 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
33
+
34
+ expect(slide1.eql?(slide2)).to be_truthy
35
+ end
36
+
37
+ it 'fails on different names' do
38
+ slide1 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
39
+ slide2 = NewSlide.new('02.erb', base_path: absolute_path('source', 'slides'))
40
+
41
+ expect(slide1.eql?(slide2)).to be_falsey
42
+ end
43
+ end
44
+
45
+ context '#similar?' do
46
+ it 'succeeds if both files share the same basename' do
47
+ slide1 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
48
+ slide2 = NewSlide.new('01.md', base_path: absolute_path('source', 'slides'))
49
+
50
+ expect(slide1).to be_similar slide2
51
+ end
52
+
53
+ it 'fails if both files do not share the same basename' do
54
+ slide1 = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
55
+ slide2 = NewSlide.new('02.erb', base_path: absolute_path('source', 'slides'))
56
+
57
+ expect(slide1).not_to be_similar slide2
58
+ end
59
+ end
60
+
61
+ context '#hash' do
62
+ it 'generates hash based on file name' do
63
+ slide = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
64
+ expect(slide).to respond_to :hash
65
+ end
66
+ end
67
+
68
+ context '#content' do
69
+ it 'evaluates template with data' do
70
+ slide = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
71
+
72
+ expect(slide.content(title: 'world')).to eq <<-EOS.strip_heredoc.chomp
73
+ <section>
74
+ <h1>
75
+ world
76
+ </h1>
77
+ </section>
78
+ EOS
79
+ end
80
+ end
81
+
82
+ context '#write' do
83
+ it 'writes content of slide to filesystem' do
84
+ slide = NewSlide.new('01.erb', base_path: absolute_path('source', 'slides'))
85
+ slide.write(title: 'world')
86
+
87
+ in_current_dir do
88
+ slide_content = File.read('source/slides/01.html.erb')
89
+
90
+ expect(slide_content).to eq <<-EOS.strip_heredoc.chomp
91
+ <section>
92
+ <h1>
93
+ world
94
+ </h1>
95
+ </section>
96
+ EOS
97
+ end
98
+ end
99
+ end
100
+
101
+ context '#to_s' do
102
+ it 'returns string representation of self' do
103
+ slide = NewSlide.new('02.md', base_path: absolute_path('source', 'slides'))
104
+
105
+ expect(slide.to_s).to eq absolute_path('source', 'slides', '02.html.md')
106
+ end
107
+ end
108
+
109
+ context '#basename' do
110
+ it 'reduces slide file name to minimum' do
111
+ slide = NewSlide.new('02.erb', base_path: absolute_path('source', 'slides'))
112
+ expect(slide.base_name).to eq '02'
113
+ end
114
+ end
115
+
116
+ context '#match?' do
117
+ it 'matches relative path' do
118
+ slide = NewSlide.new('02.md', base_path: absolute_path('source', 'slides'))
119
+
120
+ expect(slide).to be_match(/02/)
121
+ end
122
+
123
+ it 'supports string' do
124
+ slide = NewSlide.new('02.md', base_path: absolute_path('source', 'slides'))
125
+
126
+ expect(slide).to be_match('02')
127
+ end
128
+ end
129
+
130
+ context '#group?' do
131
+ it 'succeeds if slide has group' do
132
+ slide = NewSlide.new('group:02.md', base_path: absolute_path('source', 'slides'))
133
+
134
+ expect(slide).to be_group 'group'
135
+ end
136
+
137
+ it 'succeeds if slide has group and no ending' do
138
+ slide = NewSlide.new('group:02', base_path: absolute_path('source', 'slides'))
139
+
140
+ expect(slide).to be_group 'group'
141
+ end
142
+
143
+ it 'succeeds if slide has same name for group and slide' do
144
+ slide = NewSlide.new('02:02', base_path: absolute_path('source', 'slides'))
145
+
146
+ expect(slide).to be_group '02'
147
+ end
148
+
149
+ it 'fails if slide has not group' do
150
+ slide = NewSlide.new('02.md', base_path: absolute_path('source'))
151
+
152
+ expect(slide).not_to be_group 'group'
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,137 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe PresentationHelper do
5
+ let(:helpers_module) do
6
+ Module.new do
7
+ def helper1
8
+ 'helper1'
9
+ end
10
+ end
11
+ end
12
+
13
+ context '#initialize' do
14
+ it 'accepts a module' do
15
+ stub_const('HelpersModule', helpers_module)
16
+ expect { PresentationHelper.new HelpersModule }.not_to raise_error
17
+ end
18
+
19
+ it 'accepts a block' do
20
+ expect { PresentationHelper.new(proc { def helper1; end }) }.not_to raise_error
21
+ end
22
+
23
+ it 'fails on other types' do
24
+ expect { PresentationHelper.new('') }.to raise_error TypeError
25
+ end
26
+ end
27
+
28
+ context '.parse' do
29
+ it 'creates helper from array of modules' do
30
+ helpers_module1 = Module.new do
31
+ def helper1
32
+ 'helper1'
33
+ end
34
+ end
35
+
36
+ helpers_module2 = Module.new do
37
+ def helper2
38
+ 'helper2'
39
+ end
40
+ end
41
+
42
+ stub_const('HelpersModule1', helpers_module1)
43
+ stub_const('HelpersModule2', helpers_module2)
44
+
45
+ helpers = PresentationHelper.parse [HelpersModule1, HelpersModule2]
46
+
47
+ expect(helpers.size).to eq 2
48
+ expect(helpers.first.available_methods).to eq [:helper1]
49
+ expect(helpers.last.available_methods).to eq [:helper2]
50
+ end
51
+
52
+ it 'creates helper from array of procs' do
53
+ proc1 = proc { def helper1; end }
54
+ proc2 = proc do
55
+ def helper2; end
56
+ end
57
+
58
+ helpers = PresentationHelper.parse [proc1, proc2]
59
+
60
+ expect(helpers.size).to eq 2
61
+ expect(helpers.first.available_methods).to eq [:helper1]
62
+ expect(helpers.last.available_methods).to eq [:helper2]
63
+ end
64
+
65
+ it 'supports mixed arrays' do
66
+ stub_const('HelpersModule', helpers_module)
67
+ proc2 = proc { def helper2; end }
68
+
69
+ helpers = PresentationHelper.parse [HelpersModule, proc2]
70
+
71
+ expect(helpers.size).to eq 2
72
+ expect(helpers.first.available_methods).to eq [:helper1]
73
+ expect(helpers.last.available_methods).to eq [:helper2]
74
+ end
75
+ end
76
+
77
+ context '#to_module' do
78
+ it 'returns self as module' do
79
+ stub_const('HelpersModule', helpers_module)
80
+ helper = PresentationHelper.new HelpersModule
81
+
82
+ expect(helper.to_module).to be_kind_of Module
83
+ end
84
+
85
+ it 'transforms if block was given' do
86
+ helper = PresentationHelper.new(proc { def helper1; end })
87
+
88
+ expect(helper.to_module).to be_kind_of Module
89
+ end
90
+ end
91
+
92
+ context '#name' do
93
+ it 'returns name' do
94
+ stub_const('HelpersModule', helpers_module)
95
+ helper = PresentationHelper.new HelpersModule
96
+
97
+ expect(helper.name).to eq 'HelpersModule'
98
+ end
99
+
100
+ it 'returns anonymous if unkown' do
101
+ helper = PresentationHelper.new proc { def helper1; end }
102
+
103
+ expect(helper.name).to eq '<Anonymous>'
104
+ end
105
+ end
106
+
107
+ context '#type' do
108
+ it 'returns module if module was given' do
109
+ stub_const('HelpersModule', helpers_module)
110
+ helper = PresentationHelper.new HelpersModule
111
+
112
+ expect(helper.type).to eq :MODULE
113
+ end
114
+
115
+ it 'returns proc if proc was given' do
116
+ helper = PresentationHelper.new proc { def helper1; end }
117
+
118
+ expect(helper.type).to eq :PROC
119
+ end
120
+ end
121
+
122
+ context '#available_methods' do
123
+ it 'extracts methods if module was given' do
124
+ stub_const('HelpersModule', helpers_module)
125
+ helper = PresentationHelper.new HelpersModule
126
+
127
+ expect(helper.available_methods).to eq [:helper1]
128
+ end
129
+
130
+ it 'extracts methods if proc was given' do
131
+ helper = PresentationHelper.new proc { def helper1; end }
132
+
133
+ expect(helper.available_methods).to eq [:helper1]
134
+ end
135
+
136
+ end
137
+ end
File without changes
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe SlideGroup do
5
+ let(:template) { double('Template') }
6
+ let(:slide1) { instance_double('Middleman::Presentation::ExistingSlide') }
7
+ let(:slide2) { instance_double('Middleman::Presentation::ExistingSlide') }
8
+
9
+ context '#initialize' do
10
+ it 'requires a name, slides and template' do
11
+ expect do
12
+ SlideGroup.new(name: 'group', slides: [slide1, slide2], template: template)
13
+ end.not_to raise_error
14
+ end
15
+ end
16
+
17
+ context '#partial_path' do
18
+ it 'returns path to group file' do
19
+ expect(slide1).to receive(:partial_path).and_return 'path1'
20
+ expect(slide2).to receive(:partial_path).and_return 'path2'
21
+
22
+ group = SlideGroup.new(name: 'group', slides: [slide1, slide2], template: template)
23
+
24
+ expect(group.partial_path).to eq '"path1", "path2"'
25
+ end
26
+ end
27
+
28
+ context '#slides' do
29
+ it 'returns slides belonging to group' do
30
+ group = SlideGroup.new(name: 'group', slides: [slide1, slide2], template: template)
31
+ expect(group.slides).to include slide1, slide2
32
+ end
33
+ end
34
+
35
+ context '#name' do
36
+ it 'returns name of group' do
37
+ group = SlideGroup.new(name: 'group', slides: [slide1, slide2], template: template)
38
+ expect(group.name).to eq 'group'
39
+ end
40
+ end
41
+
42
+ context '#renders' do
43
+ it 'renders slides and uses template' do
44
+ block = proc { |_partial_path| }
45
+
46
+ expect(slide1).to receive(:render) { |&passed_block| expect(block).to be passed_block }.and_return('01')
47
+ expect(slide2).to receive(:render) { |&passed_block| expect(block).to be passed_block }.and_return('02')
48
+ expect(template).to receive(:result).with(slides: "01\n02")
49
+
50
+ group = SlideGroup.new(name: 'group', slides: [slide1, slide2], template: template)
51
+ group.render(&block)
52
+ end
53
+ end
54
+ end