frontman-ssg 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +42 -0
  3. data/.github/CODE_OF_CONDUCT.md +9 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +25 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  7. data/.gitignore +5 -0
  8. data/.rubocop.yml +88 -0
  9. data/CHANGELOG.md +11 -0
  10. data/CONTRIBUTING.md +42 -0
  11. data/Gemfile +5 -0
  12. data/LICENSE.md +21 -0
  13. data/Rakefile +94 -0
  14. data/SECURITY.md +6 -0
  15. data/bin/frontman +6 -0
  16. data/frontman-ssg.gemspec +48 -0
  17. data/frontman.svg +2 -0
  18. data/lib/frontman.rb +15 -0
  19. data/lib/frontman/app.rb +175 -0
  20. data/lib/frontman/bootstrapper.rb +70 -0
  21. data/lib/frontman/builder/asset_pipeline.rb +55 -0
  22. data/lib/frontman/builder/builder.rb +193 -0
  23. data/lib/frontman/builder/file.rb +55 -0
  24. data/lib/frontman/builder/mapping.rb +54 -0
  25. data/lib/frontman/builder/statistics_collector.rb +37 -0
  26. data/lib/frontman/cli.rb +6 -0
  27. data/lib/frontman/commands/build.rb +76 -0
  28. data/lib/frontman/commands/init.rb +58 -0
  29. data/lib/frontman/commands/serve.rb +110 -0
  30. data/lib/frontman/concerns/dispatch_events.rb +56 -0
  31. data/lib/frontman/concerns/forward_calls_to_app.rb +28 -0
  32. data/lib/frontman/config.rb +52 -0
  33. data/lib/frontman/context.rb +125 -0
  34. data/lib/frontman/custom_struct.rb +44 -0
  35. data/lib/frontman/data_store.rb +106 -0
  36. data/lib/frontman/data_store_file.rb +60 -0
  37. data/lib/frontman/helpers/app_helper.rb +18 -0
  38. data/lib/frontman/helpers/link_helper.rb +35 -0
  39. data/lib/frontman/helpers/render_helper.rb +76 -0
  40. data/lib/frontman/helpers/url_helper.rb +11 -0
  41. data/lib/frontman/iterator.rb +48 -0
  42. data/lib/frontman/process/chain.rb +43 -0
  43. data/lib/frontman/process/processor.rb +11 -0
  44. data/lib/frontman/renderers/erb_renderer.rb +21 -0
  45. data/lib/frontman/renderers/haml_renderer.rb +22 -0
  46. data/lib/frontman/renderers/markdown_renderer.rb +26 -0
  47. data/lib/frontman/renderers/renderer.rb +26 -0
  48. data/lib/frontman/renderers/renderer_resolver.rb +26 -0
  49. data/lib/frontman/resource.rb +279 -0
  50. data/lib/frontman/sitemap_tree.rb +211 -0
  51. data/lib/frontman/toolbox/timer.rb +49 -0
  52. data/lib/frontman/version.rb +6 -0
  53. data/project-templates/default/.gitignore +2 -0
  54. data/project-templates/default/Gemfile +3 -0
  55. data/project-templates/default/config.rb +17 -0
  56. data/project-templates/default/data/site.yml +4 -0
  57. data/project-templates/default/helpers/site_helper.rb +7 -0
  58. data/project-templates/default/public/code.css +77 -0
  59. data/project-templates/default/public/frontman-logo.svg +2 -0
  60. data/project-templates/default/public/main.css +27 -0
  61. data/project-templates/default/public/main.js +1 -0
  62. data/project-templates/default/source/index.html.md.erb +7 -0
  63. data/project-templates/default/source/sitemap.xml.erb +11 -0
  64. data/project-templates/default/views/layouts/main.erb +19 -0
  65. data/project-templates/default/views/layouts/main.haml +15 -0
  66. data/project-templates/default/views/partials/menu.erb +7 -0
  67. data/project-templates/webpack/.gitignore +4 -0
  68. data/project-templates/webpack/Gemfile +3 -0
  69. data/project-templates/webpack/README.md +54 -0
  70. data/project-templates/webpack/assets/css/code.css +77 -0
  71. data/project-templates/webpack/assets/css/style.css +27 -0
  72. data/project-templates/webpack/assets/images/.gitkeep +0 -0
  73. data/project-templates/webpack/assets/images/frontman_logo.svg +2 -0
  74. data/project-templates/webpack/assets/js/index.js +1 -0
  75. data/project-templates/webpack/config.rb +24 -0
  76. data/project-templates/webpack/data/site.yml +4 -0
  77. data/project-templates/webpack/helpers/assets_helper.rb +24 -0
  78. data/project-templates/webpack/helpers/site_helper.rb +7 -0
  79. data/project-templates/webpack/package-lock.json +7603 -0
  80. data/project-templates/webpack/package.json +34 -0
  81. data/project-templates/webpack/source/index.html.md.erb +7 -0
  82. data/project-templates/webpack/source/sitemap.xml.erb +11 -0
  83. data/project-templates/webpack/views/layouts/main.erb +20 -0
  84. data/project-templates/webpack/views/layouts/main.haml +14 -0
  85. data/project-templates/webpack/views/partials/menu.erb +7 -0
  86. data/project-templates/webpack/views/partials/script_with_vendors.haml +5 -0
  87. data/project-templates/webpack/webpack/base.config.js +51 -0
  88. data/project-templates/webpack/webpack/dev.config.js +6 -0
  89. data/project-templates/webpack/webpack/prod.config.js +30 -0
  90. data/readme.md +80 -0
  91. data/sorbet/config +2 -0
  92. data/sorbet/rbi/hidden-definitions/errors.txt +27259 -0
  93. data/sorbet/rbi/hidden-definitions/hidden.rbi +45122 -0
  94. data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +276 -0
  95. data/sorbet/rbi/todo.rbi +6 -0
  96. data/spec/frontman/app_spec.rb +48 -0
  97. data/spec/frontman/bootstrapper_spec.rb +26 -0
  98. data/spec/frontman/builder/builder_spec.rb +79 -0
  99. data/spec/frontman/builder/file_spec.rb +45 -0
  100. data/spec/frontman/builder/mapping_spec.rb +8 -0
  101. data/spec/frontman/concerns/dispatch_events_spec.rb +70 -0
  102. data/spec/frontman/concerns/forward_calls_to_app_spec.rb +21 -0
  103. data/spec/frontman/config_spec.rb +54 -0
  104. data/spec/frontman/context_spec.rb +48 -0
  105. data/spec/frontman/custom_struct_spec.rb +51 -0
  106. data/spec/frontman/data_store_file_spec.rb +9 -0
  107. data/spec/frontman/data_store_spec.rb +36 -0
  108. data/spec/frontman/frontman_ssg_spec.rb +7 -0
  109. data/spec/frontman/helpers/app_helper_spec.rb +24 -0
  110. data/spec/frontman/helpers/link_helper_spec.rb +37 -0
  111. data/spec/frontman/helpers/render_helper_spec.rb +55 -0
  112. data/spec/frontman/helpers/url_helper_spec.rb +21 -0
  113. data/spec/frontman/iterator_spec.rb +47 -0
  114. data/spec/frontman/mocks/asset.css +3 -0
  115. data/spec/frontman/mocks/config.rb +0 -0
  116. data/spec/frontman/mocks/helpers/formatting_helper.rb +5 -0
  117. data/spec/frontman/mocks/helpers/language_helper.rb +5 -0
  118. data/spec/frontman/mocks/helpers/link_helper.rb +5 -0
  119. data/spec/frontman/mocks/helpers/test_command.rb +5 -0
  120. data/spec/frontman/mocks/html_file.html +8 -0
  121. data/spec/frontman/mocks/html_file.html.md.erb +9 -0
  122. data/spec/frontman/mocks/html_file.md.html +8 -0
  123. data/spec/frontman/mocks/info.yml +4 -0
  124. data/spec/frontman/mocks/layouts/raw_without_body.haml +1 -0
  125. data/spec/frontman/mocks/nested/data.yml +4 -0
  126. data/spec/frontman/mocks/nested/more_data.yml +4 -0
  127. data/spec/frontman/mocks/partials/paragraph.haml +2 -0
  128. data/spec/frontman/mocks/snippet/html_file.html +8 -0
  129. data/spec/frontman/mocks/snippet/html_file.yml +670 -0
  130. data/spec/frontman/mocks/test.html +8 -0
  131. data/spec/frontman/mocks/wrap.haml +3 -0
  132. data/spec/frontman/process/chain_spec.rb +56 -0
  133. data/spec/frontman/renderers/erb_renderer_spec.rb +22 -0
  134. data/spec/frontman/renderers/haml_renderer_spec.rb +12 -0
  135. data/spec/frontman/renderers/markdown_renderer_spec.rb +12 -0
  136. data/spec/frontman/renderers/renderer_spec.rb +16 -0
  137. data/spec/frontman/resource_spec.rb +151 -0
  138. data/spec/frontman/sitemap_tree_spec.rb +128 -0
  139. data/spec/frontman/toolbox/timer_spec.rb +34 -0
  140. data/spec/spec_setup.rb +19 -0
  141. metadata +507 -0
@@ -0,0 +1,8 @@
1
+
2
+ <!DOCTYPE html> <html lang=en> <head> <title> Quick Start | Magento 1 extension | Algolia Documentation </title>
3
+ </head> <body class=relative><main class='lg:max-w-648 min-h-full w-full'> <div class='text-grey-1000 leading-normal'> <section class=mb-48> <div class="mb-4 flex justify-between"> <div class="text-xs leading-tight"> <div class="font-sans-alt uppercase font-semibold tracking-wide"> Integrations / Extensions / <span class=text-nebula-500>Magento 1</span> </div> </div> <div class="flex items-center uppercase font-semibold tracking-wide text-grey-1000-opacity-30 text-xs leading-tight whitespace-no-wrap font-sans-alt"> <span class="block mr-4 w-16 h-16 fill-current"> <span class="block p-2"> <svg class="block h-full" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22"><path d="M11,22A11,11,0,1,1,22,11,11,11,0,0,1,11,22ZM11,2a9,9,0,1,0,9,9A9,9,0,0,0,11,2Z"/><path d="M15,14a.93.93,0,0,1-.45-.11l-4-2A1,1,0,0,1,10,11V5a1,1,0,0,1,2,0v5.38l3.45,1.73a1,1,0,0,1,.44,1.34A1,1,0,0,1,15,14Z"/></svg> </span> </span> Feb. 15, 2019 </div> </div> <div class="flex justify-between"> <h1 class="md:text-4xl lg:text-5xl text-3xl leading-tall tracking-tight font-bold hyphenated"> Quick Start </h1> <div class="mt-16 ml-16"> <a class='edit-link w-24 h-24 items-center justify-center bg-grey-400-opacity-40 hover:bg-grey-400-opacity-60 rounded-full transition-fast-out hidden' href='https://github.com/algolia/doc/edit/master/source/doc/integration/magento-1/1-getting-started/1-quick-start.html.md.erb' rel=noopener target=_blank> <span class='flex items-center justify-center w-16 h-16 text-grey-700 fill-current'> <svg class=h-full xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32.58 31.77"><path d="M16.29,0a16.29,16.29,0,0,0-5.15,31.75c.82.15,1.11-.36,1.11-.79s0-1.41,0-2.77C7.7,29.18,6.74,26,6.74,26a4.36,4.36,0,0,0-1.81-2.39c-1.47-1,.12-1,.12-1a3.43,3.43,0,0,1,2.49,1.68,3.48,3.48,0,0,0,4.74,1.36,3.46,3.46,0,0,1,1-2.18c-3.62-.41-7.42-1.81-7.42-8a6.3,6.3,0,0,1,1.67-4.37,5.94,5.94,0,0,1,.16-4.31s1.37-.44,4.48,1.67a15.41,15.41,0,0,1,8.16,0c3.11-2.11,4.47-1.67,4.47-1.67A5.91,5.91,0,0,1,25,11.07a6.3,6.3,0,0,1,1.67,4.37c0,6.26-3.81,7.63-7.44,8a3.85,3.85,0,0,1,1.11,3c0,2.18,0,3.94,0,4.47s.29.94,1.12.78A16.29,16.29,0,0,0,16.29,0Z"/></svg> <span aria-hidden=true class=hidden> Edit this guide </span> </span> </a> </div> </div> </section> <div class='content mb-32'> <section> <p>To get started using Algolia in your Magento installation, just follow the steps in this video or on the page below.</p> <div class="flex transition-fast-in-out items-center" data-video=true> <div class="group embed flex-no-grow flex-no-shrink md:w-248 border-l-4 border-solid border-red-500-opacity-80 shadow-md rounded-r overflow-hidden mt-0 mb-0 transition-fast-in-out" data-video-container=DUuv9ALS5cM> <div class=embed-item data-video-frame=DUuv9ALS5cM data-video-start=0 id=DUuv9ALS5cM></div> <div class="absolute pin bg-center bg-cover pointer-events-none flex items-center justify-center" data-video-thumbnail=true style="background-image: url(https://img.youtube.com/vi/DUuv9ALS5cM/hqdefault.jpg)"> <div class="py-16 px-32 rounded-lg bg-gradient-red-400-red-500 shadow group-hover:shadow-md cursor-pointer transition-fast-out"> <div class="m-4 h-24 text-white"> <div class="h-full fill-current"> <svg class="block h-full" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 10"><polygon points="0 0 0 10 8 5 0 0"/></svg> </div> </div> </div> </div> </div> <div class="ml-32 md:block hidden" data-video-description=true> <div> <div class="mb-8 text-grey-1000 font-bold text-lg"> Algolia Instant Search on your Magento Store </div> <div class=text-grey-400> By Algolia, 17 min </div> </div> </div> </div> <h2 id=installation>Installation</h2> <p>There are two possible ways to install the extension:</p> <ol> <li>Through <a href="https://github.com/colinmollenhour/modman">modman</a></li> <li>Through <a href="https://marketplace.magento.com/algolia-algoliasearch.html">Magento Marketplace</a></li> </ol> <h3 id=modman>Modman</h3> <p>With <a href="https://github.com/colinmollenhour/modman">modman</a> installed, run the following commands:</p> <div class=snippet-wrapper><div class=snippet-actions markdown=0><div class="copy-link snippet-action btn-satellite btn-satellite-white ml-8">Copy</div></div><div class=snippet-header><div class="nav nav-tabs snippet-tabs" markdown=0><span class="snippet-tab-wrapper snippet-tab-wrapper-active"><a href="#snippet_bash" data-toggle=tab class=snippet-tab>bash</a></span></div></div><div id=snippet_bash data-tab-pane class="snippet-body snippet-body-active" data-active=true data-language=bash><div class=highlight><pre class="highlight shell"><code><span class="nb">cd</span> /path/to/your/magento/directory
4
+ modman init
5
+ modman clone https://github.com/algolia/algoliasearch-magento.git
6
+ </code></pre></div></div></div> <h3 id=magento-marketplace>Magento Marketplace</h3> <p>Navigate to the <a href="https://marketplace.magento.com/algolia-algoliasearch.html">Magento Marketplace</a> to get the extension and follow the instructions to install.</p> <h2 id=configuration>Configuration</h2> <p>Before Algolia can be used with Magento, an Algolia account is needed. With the account, it’s possible to configure the Magento extension to work properly.</p> <h3 id=algolia-account>Algolia account</h3> <p>An account can be created in the <a href="/users/sign_up">sign-up wizard</a>.</p> <p class="alert alert-info">Pay attention while picking a data center during the sign-up. For performance reasons, it’s best to pick the one closest to the data center of your Magento installation.</p> <h3 id=magento-settings>Magento settings</h3> <p>To configure the Magento extension, you will need the following Algolia credentials:</p> <ul> <li>Application ID</li> <li><a href="/doc/guides/security/api-keys/#search-only-api-key">Search-only API key</a></li> <li><a href="/doc/guides/security/api-keys/#admin-api-key">Admin API key</a></li> </ul> <p>These credentials can be found on the <a href="/dashboard">Algolia Dashboard</a>, on the <strong>API keys</strong> page from the menu.</p> <p>In the administration section of your Magento project, navigate to <strong>System &gt; Configuration &gt; Catalog &gt; Algolia Search</strong> and fill in the form with all the information required.</p> <figure> <p><img src="/doc/assets/images/integrations/magento-1/getting-started/configuration-ef05486e.png" alt="Basic information configuration"/></p> </figure> </section> <section> <h2 id=indexing>Indexing</h2> <p>With the extension configured, the data in your Magento installation should be pushed to Algolia for the first time by a process called <a href="/doc/guides/getting-started/how-algolia-works/in-depth/implementation-process/#indexing-data"><em>indexing</em></a>. This can be accomplished by navigating to <strong>System &gt; Indexing Management</strong>. On this page, a list of indices will show up for which the <strong>Reindex Data</strong> link has to be clicked:</p> <ul> <li>Algolia Search Products</li> <li>Algolia Search Categories</li> <li>Algolia Search Pages</li> <li>Algolia Search Suggestions</li> </ul> <p>When the indexing is done, the search should now be available in your Magento installation.</p> <figure> <p><img src="/doc/assets/images/integrations/magento-1/getting-started/indexers-a88f04f2.png" alt="Magento store indexers"/></p> </figure> </section> </div> <div class=mt-88>
7
+ </div></div></main></body>
8
+ </html>
@@ -0,0 +1,3 @@
1
+
2
+ = wrap_layout 'raw_without_body.haml' do
3
+ %h1 This is a test!
@@ -0,0 +1,56 @@
1
+ # typed: false
2
+ # frozen_string_literal: false
3
+
4
+ require './spec/spec_setup'
5
+ require 'frontman/process/chain'
6
+ require 'frontman/process/processor'
7
+
8
+ describe Frontman::Process::Chain do
9
+ it 'should not manipulate data when there are no processors' do
10
+ data = 'foobar'
11
+ subject.process(data)
12
+
13
+ expect(data).to eq 'foobar'
14
+ end
15
+
16
+ it 'should pass data through all processors' do
17
+ subject.add_processors([processor_factory(lambda { |string|
18
+ string << 'CASE'
19
+ }), processor_factory(lambda { |string|
20
+ string.downcase!
21
+ })])
22
+
23
+ data = 'down'
24
+ subject.process(data)
25
+ expect(data).to eq 'downcase'
26
+ end
27
+
28
+ it 'should map over all processors and return the proper result' do
29
+ subject.add_processors(
30
+ [
31
+ processor_factory(->(_) { 'foo' }),
32
+ processor_factory(->(_) { 'bar' })
33
+ ]
34
+ )
35
+
36
+ expect(subject.process(nil)).to eq %w[foo bar]
37
+ end
38
+ end
39
+
40
+ class Processor < Frontman::Process::Processor
41
+ attr_accessor :callback
42
+
43
+ def on_process(callback)
44
+ @callback = callback
45
+ end
46
+
47
+ def process(data)
48
+ @callback.call(data)
49
+ end
50
+ end
51
+
52
+ def processor_factory(on_process)
53
+ processor = Processor.new
54
+ processor.on_process(on_process)
55
+ processor
56
+ end
@@ -0,0 +1,22 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/renderers/erb_renderer'
6
+
7
+ describe Frontman::ErbRenderer do
8
+ it 'should render ERB correctly' do
9
+ compiled = Frontman::ErbRenderer.instance.compile("t<%= 'es' %>t")
10
+ expect(Frontman::ErbRenderer.instance.render_content(compiled, nil, Frontman::Context.new, {})).to eq 'test'
11
+ end
12
+
13
+ it 'should throw an error with incorrect ERB syntax' do
14
+ compiled = Frontman::ErbRenderer.instance.compile('t<%= |! %> t')
15
+ expect { Frontman::ErbRenderer.instance.render_content(compiled, nil, Frontman::Context.new, {}) }.to raise_error SyntaxError
16
+ end
17
+
18
+ it 'should send the data to the view' do
19
+ compiled = Frontman::ErbRenderer.instance.compile('t<%= string %>t')
20
+ expect(Frontman::ErbRenderer.instance.render_content(compiled, nil, Frontman::Context.new, string: 'es')).to eq 'test'
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/renderers/haml_renderer'
6
+
7
+ describe Frontman::HamlRenderer do
8
+ it 'should render HAML correctly' do
9
+ compiled = Frontman::HamlRenderer.instance.compile('%h1#hello Hello!')
10
+ expect(Frontman::HamlRenderer.instance.render_content(compiled, nil, Frontman::Context.new, {})).to eq "<h1 id='hello'>Hello!</h1>\n"
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/renderers/markdown_renderer'
6
+
7
+ describe Frontman::MarkdownRenderer do
8
+ it 'should render Markdown correctly' do
9
+ compiled = Frontman::MarkdownRenderer.instance.compile('# Hello!')
10
+ expect(Frontman::MarkdownRenderer.instance.render_content(compiled, nil, nil, {})).to eq "<h1 id=\"hello\">Hello!</h1>\n"
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/renderers/renderer'
6
+
7
+ describe Frontman::Renderer do
8
+ it 'should raise an error when we try to compile' do
9
+ expect { Frontman::Renderer.instance.compile('fakelayout') }.to raise_error RuntimeError
10
+ end
11
+
12
+ it 'should raise an error when we try to render content' do
13
+ mock = 'fake'
14
+ expect { Frontman::Renderer.instance.render_content(mock, mock, mock, mock) }.to raise_error RuntimeError
15
+ end
16
+ end
@@ -0,0 +1,151 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/resource'
6
+
7
+ describe Frontman::Resource do
8
+ it 'should throw an error when creating a Frontman::Resource from a non-existing file' do
9
+ expect { Frontman::Resource.from_path('non-existing-file') }.to raise_error RuntimeError
10
+ end
11
+
12
+ it 'should load the Frontman::Resource' do
13
+ expect(Frontman::Resource.from_path('spec/frontman/mocks/html_file.html').class.name).to eq 'Frontman::Resource'
14
+ end
15
+
16
+ it 'should cache the Frontman::Resource' do
17
+ Frontman::Resource.from_path('spec/frontman/mocks/html_file.html')
18
+ expect(Frontman::Resource.resources['spec/frontman/mocks/html_file.html'.gsub(%r{^/}, '')].class.name).to eq 'Frontman::Resource'
19
+ end
20
+
21
+ it 'should generate Frontman::Resources with different destinations and the same source file' do
22
+ Frontman::Resource.from_path('spec/frontman/mocks/html_file.html')
23
+ Frontman::Resource.from_path('spec/frontman/mocks/html_file.html', 'testing/bar.html')
24
+ expect(Frontman::Resource.resources['spec/frontman/mocks/html_file.html'.gsub(%r{^/}, '')].class.name).to eq 'Frontman::Resource'
25
+ expect(Frontman::Resource.resources['testing/bar.html'.gsub(%r{^/}, '')].class.name).to eq 'Frontman::Resource'
26
+ end
27
+
28
+ subject { Frontman::Resource.from_path('spec/frontman/mocks/html_file.md.html') }
29
+ context 'parse_resource' do
30
+ it 'should reset the view data' do
31
+ subject.data = { foo: 'bar' }.to_ostruct
32
+ expect(subject.data.length).to eq 1
33
+ subject.parse_resource
34
+ expect(subject.data.length).to eq 0
35
+ end
36
+
37
+ it 'should append passed data' do
38
+ subject.data = { foo: 'bar' }.to_ostruct
39
+ expect(subject.data.length).to eq 1
40
+ subject.parse_resource(false, foo: 'bar')
41
+ expect(subject.data.length).to eq 1
42
+ end
43
+
44
+ it 'should mark the Frontman::Resource as indexable when not set' do
45
+ expect(subject.indexable?).to eq true
46
+ end
47
+
48
+ it 'should mark the Frontman::Resource as not indexable when set to false' do
49
+ subject.data = { indexable: false }.to_ostruct
50
+
51
+ expect(subject.indexable?).to eq false
52
+ end
53
+
54
+ it 'should mark the Frontman::Resource as indexable when explicitly set to true' do
55
+ subject.data = { indexable: true }.to_ostruct
56
+
57
+ expect(subject.indexable?).to eq true
58
+ end
59
+
60
+ it 'should compile the view when it has just one renderer' do
61
+ subject.parse_resource
62
+ expect(subject.renderers.length).to eq 1
63
+ expect(subject.compiled.class.name).to eq 'Kramdown::Document'
64
+ end
65
+
66
+ let(:multiRenderer) { Frontman::Resource.from_path('spec/frontman/mocks/html_file.html.md.erb') }
67
+
68
+ it 'should not compile when it has multiple renderers' do
69
+ multiRenderer.parse_resource
70
+ expect(multiRenderer.renderers.length).to eq 2
71
+ expect(multiRenderer.compiled.class.name).to eq 'NilClass'
72
+ end
73
+ end
74
+
75
+ it 'should find the correct layout' do
76
+ Frontman::App.instance.register_layout('spec/frontman/*', 'correct_layout')
77
+ expect(subject.layout).to eq 'views/layouts/correct_layout'
78
+ end
79
+
80
+ it 'should split extensions correctly' do
81
+ expect(subject.strip_extensions('testing/file.foo.bar.baz')).to eq ['testing/file', %w[foo bar baz]]
82
+ end
83
+
84
+ it 'should parse an existing snippet file' do
85
+ resource = Frontman::Resource.from_path('spec/frontman/mocks/snippet/html_file.html')
86
+ resource.parse_data_file
87
+ expect(resource.data.yml.length).to eq 2
88
+ end
89
+
90
+ it 'should have a modified-time' do
91
+ expect(subject.mtime).to be > Time.new(2019, 0o1, 0o1)
92
+ end
93
+
94
+ context 'Strip Extensions' do
95
+ it 'should properly strip extensions from paths with no extensions' do
96
+ path, extensions = subject.strip_extensions('fake/file/path')
97
+ expect(path).to eq 'fake/file/path'
98
+ expect(extensions.length).to eq 0
99
+ end
100
+
101
+ it 'should properly strip extensions from paths with one extension' do
102
+ path, extensions = subject.strip_extensions('fake/file/path.mock')
103
+ expect(path).to eq 'fake/file/path'
104
+ expect(extensions).to eq %w[mock]
105
+ end
106
+
107
+ it 'should properly strip extensions from paths with multiple extensions' do
108
+ path, extensions = subject.strip_extensions('fake/file/path.mock.foo.bar')
109
+ expect(path).to eq 'fake/file/path'
110
+ expect(extensions).to eq %w[mock foo bar]
111
+ end
112
+
113
+ it 'should not strip the extension if part of the path has a dot in it' do
114
+ path, extensions = subject.strip_extensions('fake/file/dot.net/path.mock.foo.bar')
115
+ expect(path).to eq 'fake/file/dot.net/path'
116
+ expect(extensions).to eq %w[mock foo bar]
117
+ end
118
+ end
119
+
120
+ context 'Setup Destination' do
121
+ it 'should set the right destination extension' do
122
+ subject.destination_path = 'path/to/file.html.md.erb'
123
+ subject.setup_destination
124
+ expect(subject.extension).to eq 'html'
125
+ end
126
+
127
+ it 'should find the right destination path for HTML files' do
128
+ subject.destination_path = 'path/to/file.html.md.erb'
129
+ subject.setup_destination
130
+ expect(subject.destination_path).to eq 'path/to/file/index.html'
131
+ end
132
+
133
+ it 'should find the right destination path for non-HTML files' do
134
+ subject.destination_path = 'path/to/file.md.erb'
135
+ subject.setup_destination
136
+ expect(subject.destination_path).to eq 'path/to/file.md'
137
+ end
138
+
139
+ it 'should find the right destination path without extension' do
140
+ subject.destination_path = 'path/to/file'
141
+ subject.setup_destination
142
+ expect(subject.destination_path).to eq 'path/to/file/index.html'
143
+ end
144
+
145
+ it 'should find the right destination path without extension' do
146
+ subject.destination_path = 'file.html.haml'
147
+ subject.setup_destination
148
+ expect(subject.destination_path).to eq 'file/index.html'
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,128 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'lib/frontman/sitemap_tree'
6
+
7
+ describe Frontman::SitemapTree do
8
+ context 'building SitemapTree' do
9
+ before(:each) do
10
+ Frontman::SitemapTree.class_variable_set :@@urls, {}
11
+ @sitemap_tree = Frontman::SitemapTree.new(nil)
12
+ end
13
+
14
+ it 'should add resources to the tree' do
15
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
16
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
17
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
18
+
19
+ expect(@sitemap_tree.flatten.size).to eq 3
20
+ end
21
+
22
+ it 'should not add js and css resources' do
23
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.js' }.to_ostruct)
24
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.css' }.to_ostruct)
25
+
26
+ expect(@sitemap_tree.flatten.size).to eq 0
27
+ end
28
+
29
+ it 'should find dir' do
30
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
31
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
32
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
33
+
34
+ expect(@sitemap_tree.find(['doc']).class).to eq Frontman::SitemapTree
35
+ expect(@sitemap_tree.find(%w[doc test test2]).class).to eq Frontman::SitemapTree
36
+ end
37
+
38
+ it 'should load @sitemap_tree from url, partial urls and resource' do
39
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
40
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
41
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
42
+
43
+ expect(@sitemap_tree.from_url('doc/test').class).to eq described_class
44
+ expect(@sitemap_tree.from_url('doc/test/test1').class).to eq described_class
45
+ expect(@sitemap_tree.from_resource({ destination_path: 'doc/test/test1.html' }.to_ostruct).class).to eq described_class
46
+ end
47
+
48
+ it 'should access parent, children, sibling, ancestors' do
49
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
50
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
51
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
52
+
53
+ tree = @sitemap_tree.from_url('doc/test/test2')
54
+
55
+ expect(tree.parent.parent.url_part).to eq 'doc'
56
+ expect(tree.children.size).to eq 2
57
+ expect(tree.children[0].siblings.size).to eq 2
58
+ expect(tree.children[0].siblings[0].url_part).to eq 'test22'
59
+ expect(tree.ancestor('doc').url_part).to eq 'doc'
60
+ expect(tree.ancestor('doc', 1).url_part).to eq 'test'
61
+ end
62
+
63
+ it 'should get the final url with a / at the beginning and end' do
64
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
65
+
66
+ tree = @sitemap_tree.from_url('doc/test/test1')
67
+
68
+ expect(tree.final_url).to eq '/doc/test/test1/'
69
+ end
70
+
71
+ it 'should proxy resources to a given url' do
72
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
73
+ @sitemap_tree.add_proxy('foo/bar.html', 'spec/frontman/mocks/html_file.html')
74
+ tree = @sitemap_tree.from_url('/foo/bar')
75
+ expect(tree.class).to eq described_class
76
+ expect(tree.resource).to be_a Frontman::Resource
77
+ end
78
+
79
+ it 'should get all the pages both nested and not nested' do
80
+ @sitemap_tree.add({ destination_path: 'doc/test/test1.html' }.to_ostruct)
81
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
82
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
83
+
84
+ expect(@sitemap_tree.get_all_pages.flatten.length).to eq 3
85
+
86
+ tree = @sitemap_tree.from_url('doc/test/test2')
87
+ expect(tree.get_all_pages.flatten.length).to eq 2
88
+ end
89
+
90
+ it 'should properly set and get the value' do
91
+ value = 'testing'
92
+ @sitemap_tree.resource = value
93
+
94
+ expect(@sitemap_tree.resource).to eq value
95
+ end
96
+
97
+ it 'should identify folders' do
98
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
99
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
100
+
101
+ tree = @sitemap_tree.from_url('doc/test/test2')
102
+ expect(tree.folder?).to eq true
103
+ end
104
+
105
+ it 'should select all the pages from a folder' do
106
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test22.html' }.to_ostruct)
107
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
108
+
109
+ tree = @sitemap_tree.from_url('doc/test/test2')
110
+ expect(tree.pages.length).to eq 2
111
+ tree.pages.each do |page|
112
+ expect(page.is_a?(Frontman::SitemapTree)).to eq true
113
+ end
114
+ end
115
+
116
+ it 'should identify non-folders' do
117
+ @sitemap_tree.add({ destination_path: 'doc/test/test2/test13.html' }.to_ostruct)
118
+
119
+ item = @sitemap_tree.from_url('doc/test/test2/test13')
120
+ expect(item.folder?).to eq false
121
+ end
122
+
123
+ it 'should raise an error when adding duplicate URLs' do
124
+ @sitemap_tree.add({ destination_path: 'doc/test/tutorials/test13.html' }.to_ostruct)
125
+ expect { @sitemap_tree.add({ destination_path: 'doc/test/tutorials/test13.html' }.to_ostruct) }.to raise_error Frontman::DuplicateResourceError
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,34 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require './spec/spec_setup'
5
+ require 'frontman/toolbox/timer'
6
+
7
+ describe Frontman::Toolbox::Timer do
8
+ it 'should create and start a timer' do
9
+ timer = Frontman::Toolbox::Timer.start
10
+ expect(timer).to be_a Frontman::Toolbox::Timer
11
+ expect(timer.started_at).to_not eq nil
12
+ expect(timer.ended_at).to eq nil
13
+ end
14
+
15
+ it 'should set the stop time correctly' do
16
+ timer = Frontman::Toolbox::Timer.start
17
+ timer.stop
18
+ expect(timer.ended_at).to_not eq nil
19
+ end
20
+
21
+ it 'should calculate the correct difference' do
22
+ timer = Frontman::Toolbox::Timer.new
23
+ start_time = timer.begin
24
+ end_time = timer.stop
25
+ expect(timer.diff).to eq(end_time - start_time)
26
+ end
27
+
28
+ it 'should show the correct output' do
29
+ timer = Frontman::Toolbox::Timer.new
30
+ start_time = timer.begin
31
+ end_time = timer.stop
32
+ expect(timer.output).to eq "Elapsed time: ~#{((end_time - start_time) * 1000).ceil} milliseconds.\n"
33
+ end
34
+ end