usmu 0.2.1 → 0.2.2

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +18 -22
  3. data/CHANGELOG.md +82 -0
  4. data/README.md +0 -8
  5. data/Rakefile +32 -0
  6. data/bin/usmu +1 -5
  7. data/lib/usmu.rb +5 -3
  8. data/lib/usmu/configuration.rb +13 -1
  9. data/lib/usmu/plugin/core.rb +35 -1
  10. data/lib/usmu/site_generator.rb +13 -13
  11. data/lib/usmu/template/helpers.rb +19 -0
  12. data/lib/usmu/template/include.rb +87 -0
  13. data/lib/usmu/template/layout.rb +198 -0
  14. data/lib/usmu/template/page.rb +22 -0
  15. data/lib/usmu/template/static_file.rb +50 -0
  16. data/lib/usmu/version.rb +1 -1
  17. data/share/init-site/.gitignore +2 -0
  18. data/share/init-site/Gemfile +6 -0
  19. data/share/init-site/layouts/html.slim +8 -0
  20. data/share/init-site/source/index.md +3 -0
  21. data/share/init-site/usmu.yml +3 -0
  22. data/test/expected-site/.dotfiletest.txt +1 -0
  23. data/test/expected-site/default.html +4 -0
  24. data/test/expected-site/embedded.html +7 -0
  25. data/test/expected-site/index.html +4 -0
  26. data/test/site/content/.dotfiletest.txt +1 -0
  27. data/test/site/includes/footer.meta.yml +2 -0
  28. data/test/site/includes/footer.slim +1 -0
  29. data/test/site/layouts/embedded.slim +2 -0
  30. data/test/site/layouts/html.slim +2 -0
  31. data/test/spec/acceptance/full_site_build.feature +7 -2
  32. data/test/spec/acceptance/steps/full_site_build_steps.rb +9 -4
  33. data/test/spec/configuration_spec.rb +35 -14
  34. data/test/spec/site_generator_spec.rb +2 -2
  35. data/test/spec/{layout_spec.rb → template/layout_spec.rb} +4 -4
  36. data/test/spec/{page_spec.rb → template/page_spec.rb} +4 -4
  37. data/test/spec/{static_file_spec.rb → template/static_file_spec.rb} +5 -5
  38. data/usmu-jruby.gemspec +1 -1
  39. data/usmu.gemspec +1 -1
  40. metadata +29 -13
  41. data/lib/usmu/layout.rb +0 -189
  42. data/lib/usmu/page.rb +0 -20
  43. data/lib/usmu/static_file.rb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8af1ee0fa144c05fa7f442c710988f5b9aed5da3
4
- data.tar.gz: d701e607de71bf181ce4a221ccddc71e019fd349
3
+ metadata.gz: 77196cca8367431f548de3b4a0ed85b2d128962c
4
+ data.tar.gz: a36c3f979f669bd89a31962bb0ab71b770b6767a
5
5
  SHA512:
6
- metadata.gz: 4a1e515b341f517f0f3b2f4dd99cb2943d2871c6c61be073a89c3eb6a348f20173fafc870cab3c297ef9f2d89bd08052790e4e34f04b6f5bfdd971f5f776cf08
7
- data.tar.gz: 59a72aeec89ff001171d69bde9974dc0ea008efc5adeb2eba457efe28787f06c66a04b434ed804470ba230ea9972b5e762a1fb61fd1b2c7d1e0749642bca3b99
6
+ metadata.gz: a0fd7552173005b61b10310b20b5d882da9ce0007477dc1a3636b19f25cb9b3a99f322d165d02471b466426ef553f4cedd141eac353256d5ee87c1b145851fee
7
+ data.tar.gz: cb155deec549610d11dda459249894a7c94c26e44a7f07089871934620094ddab809895c7a6cd3060ddf3cff110b410b7264200cdeedf382e8411e64cad950c0
data/.travis.yml CHANGED
@@ -5,33 +5,29 @@ rvm:
5
5
  - 2.0
6
6
  - 2.1
7
7
  - ruby-head
8
- - jruby-19mode
9
- - jruby-head
10
- - rbx-2
11
- - rbx-head
12
- gemfile:
13
- - Gemfile
14
- - Gemfile-jruby
8
+ - mruby-head
9
+ - rbx-2.1
10
+ - rbx-2.2
11
+ - rbx-2.3
12
+ - rbx-2.4
15
13
  matrix:
16
- exclude:
17
- - rvm: 1.9.3
18
- gemfile: Gemfile-jruby
19
- - rvm: 2.0
20
- gemfile: Gemfile-jruby
21
- - rvm: 2.1
14
+ include:
15
+ - rvm: jruby
22
16
  gemfile: Gemfile-jruby
23
- - rvm: ruby-head
17
+ - rvm: jruby
24
18
  gemfile: Gemfile-jruby
25
- - rvm: jruby-19mode
26
- gemfile: Gemfile
19
+ env: JRUBY_OPTS='--2.0'
27
20
  - rvm: jruby-head
28
- gemfile: Gemfile
29
- - rvm: rbx-2
30
21
  gemfile: Gemfile-jruby
31
- - rvm: rbx-head
22
+ - rvm: jruby-head
32
23
  gemfile: Gemfile-jruby
24
+ env: JRUBY_OPTS='--2.0'
33
25
  allow_failures:
34
- - rvm: jruby-19mode
26
+ - rvm: 1.9.3
27
+ - rvm: jruby
35
28
  - rvm: jruby-head
36
- - rvm: rbx-2
37
- - rvm: rbx-head
29
+ - rvm: mruby-head
30
+ - rvm: rbx-2.1
31
+ - rvm: rbx-2.2
32
+ - rvm: rbx-2.3
33
+ - rvm: rbx-2.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,82 @@
1
+ # Usmu Change Log
2
+
3
+ ## 0.2.1
4
+
5
+ Matthew Scharley <matt.scharley@gmail.com>
6
+
7
+ * Add a proper description to the gemspecs (a0830bdb81582b5d2cf2c60215d725a8a47c8086)
8
+
9
+ ## 0.2.0
10
+
11
+ Matthew Scharley <matt.scharley@gmail.com>
12
+
13
+ * Add a logging library and a bunch of default messages (2691935b5a519378dbf41539f610bea58bc12f63)
14
+ * Add a few basic commandline options (833098ae38f22b3699bc411ee806d26a4b36f1d9)
15
+ * Update mtime in destination folder from source folder (558d03efd4f4f3875c7cf5b99ff18ec69cf5ba45)
16
+ * Move contributing information to it's own file for GitHub's sake (f241549ced0c8804d406685a7d5877e7eb597262)
17
+ * Add basic plugin loading. (a6fdad0e0331b7daa679db99c7c00e7fc1543363)
18
+ * Fix issues with 'layout' as a default metadata property (9ae696aa9237adc5ba8048957eefcd4fb8f7782c)
19
+ * Implement simplecov for rspec tests (606841eeed2e30801313aee56a815644f901a1b4)
20
+ * Fix output extensions for all templates I know the answer for. (bad1eed984a634f1dd28ce198fa1e40a10b2c9c8)
21
+ * Clean up configuration and simplecov a bit (bf4288e6155fdab9354616e65e5531e9a4e7ca0f)
22
+ * Clean up coverage statistics a bit that were scewed (734563c8b627da33d853e453437790b4ca64b7a2)
23
+ * Add tests for the CLI interface (8e1a520ed74000b180e780121a426f4fea55ad56)
24
+ * Add guard for quick feedback on tests (7bae19eaad9728968e764ea237ee3dd6f0cd03ce)
25
+ * Updates so specs can be run individually (6071120890347fd2c04bcfb4e8387d4b1dd839ba)
26
+ * Use turnip for the few gherkin scripts we have (d018752de127c788ec79d1a65df12e4d1b3f03d3)
27
+ * Remove cucumber from the CI task (d4094db005db5205542eb8256e86f01d9cd49d05)
28
+ * Allow the rspec rake task to find it's own spec files (35d6f7e4486f14034544884090b5cccfd7bd82ad)
29
+ * Use Redcarpet 3.2! (5c7a9d34f5ec2c12089b1e045e174f26f34877f2)
30
+ * [GH-7] Allow for excluding files via usmu.conf (da0f1123316ce1cede23a63cea8e6c46c3a17a01)
31
+ * Add one more guard test on exclude globs (143460ea5f5427845e01119a8aba039207382a1b)
32
+ * [GH-5] Add an initial pass at a plugin system (73588da4bfaf03fa27a47747b56f6e31d95c8704)
33
+ * [GH-5] Transition to commander instead of trollop and make `generate` an official command (1aaaf43c0884c70980af3b7e6fcaa8ce57f7474c)
34
+ * 1.9.3 compatibility (cba51ad465576ac542111d200cfcbb62835c097c)
35
+ * Re-enable 1.9.3 CI and add some compat notes to the readme (cf34053aaaf6a85752ec8be70f7c9969a89990d9)
36
+ * Bump to 0.2.0 release (7e7dde04c180b5ae63268db647ba45ef63a6b3f3)
37
+
38
+ ## 0.1.0
39
+
40
+ Matthew Scharley <matt.scharley@gmail.com>
41
+
42
+ * Add some gems for testing (638e064d1bfbababf2a89a6197a6ac692dcba127)
43
+ * Add an empty RSpec and Cucumber configuration with no tests (469881ef414558f27abf753335470564fd95c2dc)
44
+ * Fix my mispellings (83b27fa4fa39453e50068d1f29ae717e6be12040)
45
+ * Add a basic overarching test for a basic generator (c48a823bbdad7171b3cd530f8345a30710aeeaba)
46
+ * Add a new embedded layout test (f982f4e3e6dfddefb1a5c952600afc1c45c57da1)
47
+ * Add empty step definitions (a6c485fbcf5da30b3d65ab40820e251da56aecc1)
48
+ * Add a bunch of information to the README (292acc057ca369e3544fb9ea0552d6e96a7b648e)
49
+ * Update names to the new 'final' name (859ca5cd1523588e6d764d96304b9e62d7b5dc6c)
50
+ * Grammar (ce48ccbc227c8a0871752cb97d296a68ad9c0139)
51
+ * Add a few more dev tools (9be06d7e8be1edea83c14f43aeea0f5c1d6aa64f)
52
+ * Fix license link (fce28223da57998980a398edc31415fa458bfd60)
53
+ * Add Cane/Yard configurations (8dc2c5d8163f4f0fcbdb7c69fb0b49aac8745fa0)
54
+ * Add a Travis CI configuration (2c78a309125e665499e0c45a6bb7e270c54282f9)
55
+ * Add Travis tag to the readme (d6f1188a8db93c991203f86b592b8f02227fe31f)
56
+ * Add configuration reading and final versions of cumumber steps (09b565c1ba5a7459a53e8c75fc0efcb29204316c)
57
+ * Start to build out some specs (8435564ee4a3adc85c45742a34a7538fd3fbe8d2)
58
+ * Only run specs on the CI for now (bff24ee9222da0e7184d77fbbff13062ef4d22ce)
59
+ * Make RSpec a little less verbose in it's successes (15fc343c9faadfefa3212f790d10d48f06e60fe0)
60
+ * Add some more options for travis (e4122c192629abff76227e218b5272fcbea1f37b)
61
+ * Allow JRuby builds to fail. (b7bc4cdea0c4060326f290e71cbf4b494105ccf0)
62
+ * Allow non-MRI builds to run but also allow them to fail (d29b17cbccf56ce1cbe9c29cc67e4db682a83230)
63
+ * Add some more specs for Usmu::Configuration (7a0ae9a1727281b9bbf78c6dcbeb4983d3c1b083)
64
+ * Add a workable Layout class (345028c1217c65ea78b7d805007c8c655d7d93e7)
65
+ * Test jruby builds (98a490e1d66cd508695b767b43075f3f2446e432)
66
+ * Disallow jruby failures (954b0eb96ddb5f4ea74066e0105e092ec8a13997)
67
+ * Use Rspec 3.1.x not 3.x (f6221fbdc0e4bb7929df3390488a3e5ed0774b5a)
68
+ * Convert layout spec to a shared example (a3047928e560d91cf50bd41939d932dc5ae5d617)
69
+ * Add a functional Page class (009d0c4c8c48a4928a3c09642a205ebe7fca9328)
70
+ * Switch from Maruku to Kramdown for jruby (8ad1336bdadb109018dd1eba35cf06a2728407ca)
71
+ * Fix jruby tests by allowing config per provider not per template type (bdab71c2b7675f7a8b9f116556332a97472ea513)
72
+ * Add a public attr_reader for name and type to Layout (011031c7663fc1e1e457ae38b69f2505b1e9a343)
73
+ * Update README with minor change in functionality (0a95ce878a77a25135f8147663758922fd2528a5)
74
+ * Stylistic fix (da849668ef37022e11d85ebaab48fa8a5ecedddd)
75
+ * Large refactor of how Layout's are initialised and a new StaticFile class (81b0f3f9d707d9d9dc866713942d47217921c67f)
76
+ * Some minor refactors inspired by cane (b2f7ed7ec78292fcd0dbfb57b13cef68103bff91)
77
+ * Successfully generate a website! (f1952e8776337626606834607db557fd0301a8e2)
78
+ * Allow jruby failures again (2926aab2dc14f6b7c35db80dc93be3a24becf7ab)
79
+ * Add documentation across the board. Yard reports 100%! (3122de04ed052a31d391845ce87251d9823a3773)
80
+ * Small stylistic change (ae008aa5492b2463774e4e4659d90666059b45e0)
81
+ * Add new custom rake tasks for building gems and fix a few small issues with the specs (5b1a4241cd9f31f39179ffaad49f7155617c0e6f)
82
+ * Bump to full 0.1.0 release (fb91c2b54f79eeaeb615f98f874c990e4cdddfd3)
data/README.md CHANGED
@@ -35,14 +35,6 @@ slim:
35
35
  :pretty: true
36
36
  ```
37
37
 
38
- ### Ruby Compatibility
39
-
40
- Officially, we support MRI 1.9.3 and onwards, however we recommend the latest versions. [1.9.3 is no longer maintained][ruby-maint]
41
- and is only supported here to help out the Rubinius and JRuby folks.
42
-
43
- We only officially support MRI, however Travis does run against both Rubinius and JRuby to track compatibility and
44
- there's a reasonable track record so far. Compatibility patches are very welcome.
45
-
46
38
  [gh-contrib]: https://github.com/usmu/usmu/graphs/contributors
47
39
  [gh-issues]: https://github.com/usmu/usmu/issues
48
40
  [license]: https://github.com/usmu/usmu/blob/master/LICENSE.md
data/Rakefile CHANGED
@@ -12,6 +12,11 @@ RSpec::Core::RakeTask.new(:spec) do |t|
12
12
  t.pattern = 'test/spec'
13
13
  end
14
14
 
15
+ desc 'Start an IRB session with local code available'
16
+ task :irb do
17
+ exec 'bundle', 'exec', 'irb', '-I', 'lib'
18
+ end
19
+
15
20
  desc 'Run all test scripts'
16
21
  task :test => [:clean, :spec]
17
22
 
@@ -21,6 +26,7 @@ task :ci => [:test]
21
26
  desc 'Clean up after tests'
22
27
  task :clean do
23
28
  [
29
+ 'tmp',
24
30
  'test/coverage',
25
31
  'test/site/site',
26
32
  current_gems,
@@ -58,3 +64,29 @@ namespace :gem do
58
64
  sh "git tag #{Usmu::VERSION}" if File.exist? '.git'
59
65
  end
60
66
  end
67
+
68
+ # (mostly) borrowed from: https://gist.github.com/mcansky/802396
69
+ desc 'generate changelog with nice clean output'
70
+ task :changelog, :since_c, :until_c do |t,args|
71
+ since_c = args[:since_c] || `git tag | head -1`.chomp
72
+ until_c = args[:until_c]
73
+ cmd=`git log --pretty='format:%ci::::%an <%ae>::::%s::::%H' #{since_c}..#{until_c}`
74
+
75
+ entries = Hash.new
76
+ changelog_content = "\#\# #{Usmu::VERSION}\n\n"
77
+
78
+ cmd.lines.each do |entry|
79
+ date, author, subject, hash = entry.chomp.split('::::')
80
+ entries[author] = Array.new unless entries[author]
81
+ day = date.split(' ').first
82
+ entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
83
+ end
84
+
85
+ # generate clean output
86
+ entries.keys.each do |author|
87
+ changelog_content += author + "\n\n"
88
+ entries[author].reverse.each { |entry| changelog_content += "* #{entry}\n" }
89
+ end
90
+
91
+ puts changelog_content
92
+ end
data/bin/usmu CHANGED
@@ -7,8 +7,4 @@ rescue LoadError
7
7
  require 'usmu/ui/console'
8
8
  end
9
9
 
10
- begin
11
- Usmu::Ui::Console.new(ARGV).execute
12
- rescue StandardError
13
- exit 1
14
- end
10
+ Usmu::Ui::Console.new(ARGV)
data/lib/usmu.rb CHANGED
@@ -72,10 +72,12 @@ end
72
72
  %W{
73
73
  usmu/version
74
74
  usmu/configuration
75
- usmu/static_file
76
- usmu/layout
77
- usmu/page
78
75
  usmu/site_generator
79
76
  usmu/plugin
80
77
  usmu/plugin/core
78
+ usmu/template/helpers
79
+ usmu/template/include
80
+ usmu/template/layout
81
+ usmu/template/page
82
+ usmu/template/static_file
81
83
  }.each { |f| require f }
@@ -58,6 +58,18 @@ module Usmu
58
58
  get_files layouts_path
59
59
  end
60
60
 
61
+ # @!attribute [r] layouts_path
62
+ # @return [String] the full path to the layouts folder
63
+ def includes_path
64
+ get_path @config['includes'] || 'includes'
65
+ end
66
+
67
+ # @!attribute [r] layouts_files
68
+ # @return [Array<String>] a list of renderable files in the layouts folder
69
+ def includes_files
70
+ get_files includes_path
71
+ end
72
+
61
73
  # An index accessor to directly access the configuration file. It should be noted that `['source']` and
62
74
  # `#source_path` and other similar pairs will have different values. `['source']` is the raw value from the
63
75
  # configuration file while the latter is a path on the system, potentially altered by the path from the current
@@ -114,7 +126,7 @@ module Usmu
114
126
  # @param [Boolean] layout is this directory a layouts_path
115
127
  # @return [Array<Usmu::Layout>, Array<Usmu::StaticFile>] Either an array of Layouts or StaticFiles in the directory
116
128
  def get_files(directory)
117
- Dir["#{directory}/**/*"].select {|f| !f.match(/\.meta.yml$/) }.map do |f|
129
+ Dir["#{directory}/**/{*,.??*}"].select {|f| !f.match(/\.meta.yml$/) }.map do |f|
118
130
  f[(directory.length + 1)..f.length]
119
131
  end.select {|f| not excluded? f}
120
132
  end
@@ -1,9 +1,13 @@
1
+ require 'fileutils'
1
2
 
2
3
  module Usmu
3
4
  class Plugin
4
5
  class Core
5
- def commands(ui, c)
6
+ def initialize
6
7
  @log = Logging.logger[self]
8
+ end
9
+
10
+ def commands(ui, c)
7
11
  @log.debug('Adding core console commands...')
8
12
  @ui = ui
9
13
  c.command(:generate) do |command|
@@ -11,6 +15,12 @@ module Usmu
11
15
  command.description = 'Generates your website using the configuration specified.'
12
16
  command.action &method(:command_generate)
13
17
  end
18
+
19
+ c.command(:init) do |command|
20
+ command.syntax = 'usmu init [path]'
21
+ command.description = 'Initialise a new website in the given path, or the current directory if none given.'
22
+ command.action &method(:command_init)
23
+ end
14
24
  end
15
25
 
16
26
  # @return [void]
@@ -18,6 +28,30 @@ module Usmu
18
28
  @site_generator = Usmu::SiteGenerator.new(@ui.configuration)
19
29
  @site_generator.generate
20
30
  end
31
+
32
+ def command_init(args, options)
33
+ @log.info("Usmu v#{Usmu::VERSION}")
34
+ @log.info('')
35
+
36
+ if args.length > 1
37
+ @log.fatal('Only one path allowed to be initialised at a time.')
38
+ raise
39
+ end
40
+
41
+ path = args.length == 1 ? args.shift : '.'
42
+ from = File.realpath(File.join(File.dirname(__FILE__), '../../../share/init-site'))
43
+
44
+ @log.info("Copying #{from} -> #{path}")
45
+ Dir["#{from}/**/{*,.??*}"].each do |file|
46
+ output_name = file[(from.length + 1)..file.length]
47
+ @log.success "Creating #{output_name}..."
48
+ unless File.directory? file
49
+ output_path = "#{path}/#{output_name}"
50
+ FileUtils.mkdir_p File.dirname(output_path) unless File.directory? File.dirname(output_path)
51
+ FileUtils.copy(file, output_path)
52
+ end
53
+ end
54
+ end
21
55
  end
22
56
  end
23
57
  end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'usmu/configuration'
3
- require 'usmu/page'
4
- require 'usmu/static_file'
3
+ require 'usmu/template/page'
4
+ require 'usmu/template/static_file'
5
5
 
6
6
  module Usmu
7
7
  # This is the class that brings everything together to generate a new website.
@@ -15,39 +15,39 @@ module Usmu
15
15
  # @!attribute [r] layouts
16
16
  # @return [Array<Usmu::Layout>] a list of layouts available in this website.
17
17
  def layouts
18
- @configuration.layouts_files.map {|l| Usmu::Layout.new(@configuration, l) }
18
+ @configuration.layouts_files.map {|l| Usmu::Template::Layout.new(@configuration, l) }
19
19
  end
20
20
 
21
21
  # @!attribute [r] renderables
22
- # @return [Array<Usmu::StaticFile>] a list of renderable files from the source folder.
22
+ # @return [Array<Usmu::Template::StaticFile>] a list of renderable files from the source folder.
23
23
  # will be a subclass of this class.
24
24
  # @see Usmu::StaticFile
25
25
  #
26
26
  # Returns a list of renderable files from the source folder.
27
27
  #
28
28
  # The only guarantee made for individual files is that they will conform to the interface defined by
29
- # Usmu::StaticFile and thus be renderable, however most files will be one of the subclasses of that class.
29
+ # Usmu::Template::StaticFile and thus be renderable, however most files will be one of the subclasses of that class.
30
30
  def renderables
31
31
  @configuration.source_files.map do |filename|
32
- if Usmu::Layout.is_valid_file? 'source', filename
33
- Usmu::Page.new(@configuration, filename)
32
+ if Usmu::Template::Layout.is_valid_file? 'source', filename
33
+ Usmu::Template::Page.new(@configuration, filename)
34
34
  else
35
- Usmu::StaticFile.new(@configuration, filename)
35
+ Usmu::Template::StaticFile.new(@configuration, filename)
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  # @!attribute [r] pages
41
- # @return [Array<Usmu::Page>] a list of pages from the source folder. This is any file in the source folder which
42
- # is not static.
41
+ # @return [Array<Usmu::Template::Page>] a list of pages from the source folder. This is any file in the source
42
+ # folder which is not static.
43
43
  def pages
44
- renderables.select {|r| r.class.name != 'Usmu::StaticFile'}
44
+ renderables.select {|r| r.class.name != 'Usmu::Template::StaticFile'}
45
45
  end
46
46
 
47
47
  # @!attribute [r] files
48
- # @return [Array<Usmu::StaticFile>] a list of static files from the source folder.
48
+ # @return [Array<Usmu::Template::StaticFile>] a list of static files from the source folder.
49
49
  def files
50
- renderables.select {|r| r.class.name == 'Usmu::StaticFile'}
50
+ renderables.select {|r| r.class.name == 'Usmu::Template::StaticFile'}
51
51
  end
52
52
 
53
53
  # Generate the website according to the configuration given.
@@ -0,0 +1,19 @@
1
+ # We really should include this, but it causes an include loop and Include has a strict dependency on Layout due to
2
+ # the inheritance structure. Oh well. Perhaps I'll think of something later.
3
+ #require 'usmu/template/include'
4
+
5
+ module Usmu
6
+ module Template
7
+ class Helpers
8
+ def initialize(configuration)
9
+ @configuration = configuration
10
+ end
11
+
12
+ def include(name, args = {})
13
+ inc = Usmu::Template::Include.find_include(@configuration, name)
14
+ inc.arguments = args
15
+ inc.render
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,87 @@
1
+ require 'usmu/template/layout'
2
+
3
+ module Usmu
4
+ module Template
5
+ # Represents a page in the source directory of the website.
6
+ class Include < Layout
7
+
8
+ private
9
+
10
+ alias :layout_metadata :metadata
11
+
12
+ public
13
+
14
+ # @!attribute [rw] arguments
15
+ # @return [Hash] the arguments associated with this include
16
+ attr_accessor :arguments
17
+
18
+ # Static method to create an include for a given configuration by it's name if it exists. This differs from
19
+ # `#initialise` in that it allows different types of values to be supplied as the name and will not fail if name
20
+ # is nil
21
+ #
22
+ # @param configuration [Usmu::Configuration] The configuration to use for the search
23
+ # @param name [String]
24
+ # If name is a string then search for a template with that name. Name here should not include
25
+ # file extension, eg. body not body.slim. If name is not a string then it will be returned verbatim. This means
26
+ # that name is nilable and can also be passed in as an Usmu::Template::Include already for testing purposes.
27
+ # @return [Usmu::Layout]
28
+ def self.find_include(configuration, name)
29
+ if name === 'none'
30
+ nil
31
+ elsif name.class.name == 'String'
32
+ Dir["#{configuration.includes_path}/#{name}.*"].each do |f|
33
+ filename = File.basename(f)
34
+ if filename != "#{name}.meta.yml"
35
+ return new(configuration, f[(configuration.includes_path.length + 1)..f.length])
36
+ end
37
+ end
38
+ nil
39
+ else
40
+ name
41
+ end
42
+ end
43
+
44
+ # @!attribute [r] metadata
45
+ # @return [Hash] the metadata associated with this layout.
46
+ #
47
+ # Returns the metadata associated with this layout.
48
+ #
49
+ # This will include any metadata from parent templates and default metadata
50
+ def metadata
51
+ meta = layout_metadata
52
+ # Includes must never allow layout inheritance.
53
+ meta['layout'] = nil
54
+
55
+ meta
56
+ end
57
+
58
+ protected
59
+
60
+ # @!attribute [r] content_path
61
+ # @return [string] the base path to the files used by this class.
62
+ #
63
+ # Returns the base path to the files used by this class.
64
+ #
65
+ # This folder should be the parent folder for the file named by the name attribute.
66
+ #
67
+ # @see #name
68
+ def content_path
69
+ @configuration.includes_path
70
+ end
71
+
72
+ private
73
+
74
+ # Utility function which collates variables to pass to the template engine.
75
+ #
76
+ # @return [Hash]
77
+ def get_variables(variables)
78
+ args = {}
79
+ arguments.each do |i, value|
80
+ args[i.class.name == 'String' ? i : i.to_s] = value
81
+ end
82
+
83
+ {'site' => @configuration}.deep_merge!(metadata).deep_merge!(args).deep_merge!(variables)
84
+ end
85
+ end
86
+ end
87
+ end