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
@@ -11,7 +11,7 @@ RSpec.describe Usmu::SiteGenerator do
11
11
 
12
12
  it 'should have a list of renderable items' do
13
13
  expect(generator.respond_to? :renderables).to eq(true)
14
- expect(generator.renderables.map {|r| r.name}.sort).to eq(%w{default.md embedded.md index.md robots.txt})
14
+ expect(generator.renderables.map {|r| r.name}.sort).to eq(%w{.dotfiletest.txt default.md embedded.md index.md robots.txt})
15
15
  end
16
16
 
17
17
  it 'should have pages' do
@@ -21,7 +21,7 @@ RSpec.describe Usmu::SiteGenerator do
21
21
 
22
22
  it 'should have files' do
23
23
  expect(generator.respond_to? :files).to eq(true)
24
- expect(generator.files.map {|f| f.name}.sort).to eq(%w{robots.txt})
24
+ expect(generator.files.map {|f| f.name}.sort).to eq(%w{.dotfiletest.txt robots.txt})
25
25
  end
26
26
 
27
27
  it 'should be able to generate a site' do
@@ -1,18 +1,18 @@
1
1
  require 'support/shared_layout'
2
- require 'usmu/layout'
2
+ require 'usmu/template/layout'
3
3
 
4
- RSpec.describe Usmu::Layout do
4
+ RSpec.describe Usmu::Template::Layout do
5
5
  it_behaves_like 'an embeddable layout'
6
6
 
7
7
  let(:configuration) { Usmu::Configuration.from_hash({}) }
8
8
 
9
9
  it 'uses the \'layouts\' folder' do
10
- layout = Usmu::Layout.new(configuration, 'html.slim', 'slim', "head\nbody", {})
10
+ layout = Usmu::Template::Layout.new(configuration, 'html.slim', 'slim', "head\nbody", {})
11
11
  expect(layout.send :content_path).to eq('layouts')
12
12
  end
13
13
 
14
14
  it 'has an input path' do
15
- layout = Usmu::Layout.new(configuration, 'html.slim', 'slim', "head\nbody", {})
15
+ layout = Usmu::Template::Layout.new(configuration, 'html.slim', 'slim', "head\nbody", {})
16
16
  expect(layout.respond_to? :input_path).to eq(true)
17
17
  expect(layout.input_path).to eq('layouts/html.slim')
18
18
  end
@@ -1,18 +1,18 @@
1
1
  require 'support/shared_layout'
2
- require 'usmu/page'
2
+ require 'usmu/template/page'
3
3
 
4
- RSpec.describe Usmu::Page do
4
+ RSpec.describe Usmu::Template::Page do
5
5
  it_behaves_like 'an embeddable layout'
6
6
 
7
7
  let(:configuration) { Usmu::Configuration.from_hash({}) }
8
8
 
9
9
  it 'uses the \'source\' folder' do
10
- page = Usmu::Page.new(configuration, 'index.md', 'md', '# test', {})
10
+ page = Usmu::Template::Page.new(configuration, 'index.md', 'md', '# test', {})
11
11
  expect(page.send :content_path).to eq('src')
12
12
  end
13
13
 
14
14
  it 'has an input path' do
15
- page = Usmu::Page.new(configuration, 'index.md', 'md', '# test', {})
15
+ page = Usmu::Template::Page.new(configuration, 'index.md', 'md', '# test', {})
16
16
  expect(page.respond_to? :input_path).to eq(true)
17
17
  expect(page.input_path).to eq('src/index.md')
18
18
  end
@@ -1,26 +1,26 @@
1
1
  require 'support/shared_layout'
2
- require 'usmu/static_file'
2
+ require 'usmu/template/static_file'
3
3
 
4
- RSpec.describe Usmu::StaticFile do
4
+ RSpec.describe Usmu::Template::StaticFile do
5
5
  it_behaves_like 'a renderable file'
6
6
 
7
7
  let(:configuration) { Usmu::Configuration.from_file('test/site/usmu.yml') }
8
8
 
9
9
  it 'uses the \'source\' folder' do
10
- file = Usmu::StaticFile.new(configuration, 'robots.txt')
10
+ file = Usmu::Template::StaticFile.new(configuration, 'robots.txt')
11
11
  rendered = file.render
12
12
  expect(rendered).to eq(File.read('test/expected-site/robots.txt'))
13
13
  end
14
14
 
15
15
  it 'has an input path' do
16
16
  configuration = Usmu::Configuration.from_hash({})
17
- page = Usmu::StaticFile.new(configuration, 'robots.txt', 'txt', '', {})
17
+ page = Usmu::Template::StaticFile.new(configuration, 'robots.txt', 'txt', '', {})
18
18
  expect(page.respond_to? :input_path).to eq(true)
19
19
  expect(page.input_path).to eq('src/robots.txt')
20
20
  end
21
21
 
22
22
  it 'has an output filename that matches input' do
23
- file = Usmu::StaticFile.new(configuration, 'robots.txt')
23
+ file = Usmu::Template::StaticFile.new(configuration, 'robots.txt')
24
24
  expect(file.output_filename).to eq('robots.txt')
25
25
  end
26
26
  end
data/usmu-jruby.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'slim', '~> 2.1'
25
+ spec.add_dependency 'slim', '~> 3.0'
26
26
  spec.add_dependency 'tilt', '~> 2.0'
27
27
  spec.add_dependency 'kramdown', '~> 1.5'
28
28
  spec.add_dependency 'deep_merge', '~> 1.0'
data/usmu.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'slim', '~> 2.1'
24
+ spec.add_dependency 'slim', '~> 3.0'
25
25
  spec.add_dependency 'tilt', '~> 2.0'
26
26
  spec.add_dependency 'redcarpet', '~> 3.2', '>= 3.2.1'
27
27
  spec.add_dependency 'deep_merge', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usmu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Scharley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-29 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tilt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -242,6 +242,7 @@ files:
242
242
  - ".simplecov"
243
243
  - ".travis.yml"
244
244
  - ".yardopts"
245
+ - CHANGELOG.md
245
246
  - CONTRIBUTING.md
246
247
  - Gemfile
247
248
  - Gemfile-jruby
@@ -253,25 +254,36 @@ files:
253
254
  - cucumber.yml
254
255
  - lib/usmu.rb
255
256
  - lib/usmu/configuration.rb
256
- - lib/usmu/layout.rb
257
- - lib/usmu/page.rb
258
257
  - lib/usmu/plugin.rb
259
258
  - lib/usmu/plugin/core.rb
260
259
  - lib/usmu/site_generator.rb
261
- - lib/usmu/static_file.rb
260
+ - lib/usmu/template/helpers.rb
261
+ - lib/usmu/template/include.rb
262
+ - lib/usmu/template/layout.rb
263
+ - lib/usmu/template/page.rb
264
+ - lib/usmu/template/static_file.rb
262
265
  - lib/usmu/ui.rb
263
266
  - lib/usmu/ui/console.rb
264
267
  - lib/usmu/version.rb
268
+ - share/init-site/.gitignore
269
+ - share/init-site/Gemfile
270
+ - share/init-site/layouts/html.slim
271
+ - share/init-site/source/index.md
272
+ - share/init-site/usmu.yml
273
+ - test/expected-site/.dotfiletest.txt
265
274
  - test/expected-site/default.html
266
275
  - test/expected-site/embedded.html
267
276
  - test/expected-site/index.html
268
277
  - test/expected-site/robots.txt
278
+ - test/site/content/.dotfiletest.txt
269
279
  - test/site/content/default.md
270
280
  - test/site/content/embedded.md
271
281
  - test/site/content/embedded.meta.yml
272
282
  - test/site/content/index.md
273
283
  - test/site/content/index.meta.yml
274
284
  - test/site/content/robots.txt
285
+ - test/site/includes/footer.meta.yml
286
+ - test/site/includes/footer.slim
275
287
  - test/site/layouts/embedded.meta.yml
276
288
  - test/site/layouts/embedded.slim
277
289
  - test/site/layouts/html.meta.yml
@@ -280,15 +292,15 @@ files:
280
292
  - test/spec/acceptance/full_site_build.feature
281
293
  - test/spec/acceptance/steps/full_site_build_steps.rb
282
294
  - test/spec/configuration_spec.rb
283
- - test/spec/layout_spec.rb
284
295
  - test/spec/mock/usmu/mock_plugin.rb
285
- - test/spec/page_spec.rb
286
296
  - test/spec/plugin/core_spec.rb
287
297
  - test/spec/plugin_spec.rb
288
298
  - test/spec/site_generator_spec.rb
289
299
  - test/spec/spec_helper.rb
290
- - test/spec/static_file_spec.rb
291
300
  - test/spec/support/shared_layout.rb
301
+ - test/spec/template/layout_spec.rb
302
+ - test/spec/template/page_spec.rb
303
+ - test/spec/template/static_file_spec.rb
292
304
  - test/spec/ui/console_spec.rb
293
305
  - usmu-jruby.gemspec
294
306
  - usmu.gemspec
@@ -317,16 +329,20 @@ signing_key:
317
329
  specification_version: 4
318
330
  summary: A static site generator with a web-based frontend for editing.
319
331
  test_files:
332
+ - test/expected-site/.dotfiletest.txt
320
333
  - test/expected-site/default.html
321
334
  - test/expected-site/embedded.html
322
335
  - test/expected-site/index.html
323
336
  - test/expected-site/robots.txt
337
+ - test/site/content/.dotfiletest.txt
324
338
  - test/site/content/default.md
325
339
  - test/site/content/embedded.md
326
340
  - test/site/content/embedded.meta.yml
327
341
  - test/site/content/index.md
328
342
  - test/site/content/index.meta.yml
329
343
  - test/site/content/robots.txt
344
+ - test/site/includes/footer.meta.yml
345
+ - test/site/includes/footer.slim
330
346
  - test/site/layouts/embedded.meta.yml
331
347
  - test/site/layouts/embedded.slim
332
348
  - test/site/layouts/html.meta.yml
@@ -335,14 +351,14 @@ test_files:
335
351
  - test/spec/acceptance/full_site_build.feature
336
352
  - test/spec/acceptance/steps/full_site_build_steps.rb
337
353
  - test/spec/configuration_spec.rb
338
- - test/spec/layout_spec.rb
339
354
  - test/spec/mock/usmu/mock_plugin.rb
340
- - test/spec/page_spec.rb
341
355
  - test/spec/plugin/core_spec.rb
342
356
  - test/spec/plugin_spec.rb
343
357
  - test/spec/site_generator_spec.rb
344
358
  - test/spec/spec_helper.rb
345
- - test/spec/static_file_spec.rb
346
359
  - test/spec/support/shared_layout.rb
360
+ - test/spec/template/layout_spec.rb
361
+ - test/spec/template/page_spec.rb
362
+ - test/spec/template/static_file_spec.rb
347
363
  - test/spec/ui/console_spec.rb
348
364
  has_rdoc:
data/lib/usmu/layout.rb DELETED
@@ -1,189 +0,0 @@
1
- require 'tilt'
2
- require 'deep_merge'
3
- require 'usmu/static_file'
4
-
5
- module Usmu
6
- # Class to represent files templated with a Tilt library. Most of the custom rendering logic is contained here.
7
- class Layout < StaticFile
8
- # @!attribute [r] type
9
- # @return [String] the type of file this is. This is used to determine which template engine to use.
10
- attr_reader :type
11
-
12
- # @param configuration [Usmu::Configuration] The configuration for the website we're generating.
13
- # @param name [String] The name of the file in the source directory.
14
- # @param type [String] The type of template to use with the file. Used for testing purposes.
15
- # @param content [String] The content of the file. Used for testing purposes.
16
- # @param metadata [String] The metadata for the file. Used for testing purposes.
17
- def initialize(configuration, name, type = nil, content = nil, metadata = nil)
18
- super(configuration, name)
19
-
20
- if type.nil?
21
- type = name.split('.').last
22
- unless ::Tilt.default_mapping[type]
23
- raise "Templates of type '#{type}' aren't currently supported by Tilt. " +
24
- 'Do you have the required gem installed?'
25
- end
26
- end
27
- @type = type
28
- path = File.join("#{content_path}", "#{name[0, name.length - type.length - 1]}")
29
-
30
- if content.nil?
31
- content = File.read("#{path}.#{type}")
32
- end
33
- @content = content
34
-
35
- if metadata.nil?
36
- meta_file = "#{path}.meta.yml"
37
- metadata = if File.exist? meta_file
38
- YAML.load_file(meta_file)
39
- else
40
- {}
41
- end
42
- end
43
- @metadata = metadata
44
-
45
- @parent = nil
46
- @parent = Layout.find_layout(configuration, self.metadata['layout'])
47
- end
48
-
49
- # @!attribute [r] metadata
50
- # @return [Hash] the metadata associated with this layout.
51
- #
52
- # Returns the metadata associated with this layout.
53
- #
54
- # This will include any metadata from parent templates and default metadata
55
- def metadata
56
- if @parent.nil?
57
- (@configuration['default meta'] || {}).dup.deep_merge!(@metadata)
58
- else
59
- @parent.metadata.deep_merge!(@metadata)
60
- end
61
- end
62
-
63
- # Renders the file with any templating language required and returns the result
64
- #
65
- # @param variables [Hash] Variables to be used in the template.
66
- # @return [String] The rendered file.
67
- def render(variables = {})
68
- content = template_class.new("#{@name}.#{@type}", 1, @configuration[provider_name]) { @content }.
69
- render(nil, get_variables(variables))
70
- has_cr = content.index("\r")
71
- content += (has_cr ? "\r\n" : "\n") if content[-1] != "\n"
72
- if @parent.nil?
73
- content
74
- else
75
- @parent.render({'content' => content})
76
- end
77
- end
78
-
79
- # @!attribute [r] input_path
80
- # @return [String] the full path to the file in the source directory
81
- def input_path
82
- File.join(content_path, @name)
83
- end
84
-
85
- # @!attribute [r] output_extension
86
- # @return [String] the extension to use with the output file.
87
- def output_extension
88
- case @type
89
- when 'erb', 'rhtml', 'erubis', 'liquid'
90
- nil
91
- when 'coffee'
92
- 'js'
93
- when 'less', 'sass', 'scss'
94
- 'css'
95
- else
96
- 'html'
97
- end
98
- end
99
-
100
- # @!attribute [r] output_filename
101
- # @return [String] the filename to use in the output directory.
102
- #
103
- # Returns the filename to use for the output directory with any modifications to the input filename required.
104
- def output_filename
105
- if output_extension
106
- @name[0..@name.rindex('.')] + output_extension
107
- else
108
- @name[0..@name.rindex('.') - 1]
109
- end
110
- end
111
-
112
- # Static method to create a layout for a given configuration by it's name if it exists. This differs from
113
- # `#initialise` in that it allows different types of values to be supplied as the name and will not fail if name
114
- # is nil
115
- #
116
- # @param configuration [Usmu::Configuration] The configuration to use for the search
117
- # @param name [String]
118
- # If name is a string then search for a template with that name. Name here should not include
119
- # file extension, eg. body not body.slim. If name is not a string then it will be returned verbatim. This means
120
- # that name is nilable and can also be passed in as an Usmu::Layout already for testing purposes.
121
- # @return [Usmu::Layout]
122
- def self.find_layout(configuration, name)
123
- if name === 'none'
124
- nil
125
- elsif name.class.name == 'String'
126
- Dir["#{configuration.layouts_path}/#{name}.*"].each do |f|
127
- filename = File.basename(f)
128
- if filename != "#{name}.meta.yml"
129
- return new(configuration, f[(configuration.layouts_path.length + 1)..f.length])
130
- end
131
- end
132
- nil
133
- else
134
- name
135
- end
136
- end
137
-
138
- # Tests if a given file is a valid Tilt template based on the filename.
139
- #
140
- # @param folder_type [String]
141
- # One of `"source"` or `"layout"` depending on where the template is in the source tree.
142
- # Not used by Usmu::Layout directly but intended to be available for future API.
143
- # @param name [String] The filename to be tested.
144
- # @return [Boolean]
145
- def self.is_valid_file?(folder_type, name)
146
- type = name.split('.').last
147
- ::Tilt.default_mapping[type] ? true : false
148
- end
149
-
150
- protected
151
-
152
- # @!attribute [r] template_class
153
- # @return [Tilt::Template] the Tilt template engine for this layout
154
- def template_class
155
- @template_class ||= ::Tilt.default_mapping[@type]
156
- end
157
-
158
- # @!attribute [r] provider_name
159
- # @return [String] the Tilt template engine's name for this layout
160
- #
161
- # Returns the Tilt template engine's name for this layout.
162
- #
163
- # This is used to determine which settings to use from the configuration file.
164
- def provider_name
165
- Tilt.default_mapping.lazy_map[@type].select {|x| x[0] == template_class.name }.first[1].split('/').last
166
- end
167
-
168
- # @!attribute [r] content_path
169
- # @return [string] the base path to the files used by this class.
170
- #
171
- # Returns the base path to the files used by this class.
172
- #
173
- # This folder should be the parent folder for the file named by the name attribute.
174
- #
175
- # @see #name
176
- def content_path
177
- @configuration.layouts_path
178
- end
179
-
180
- private
181
-
182
- # Utility function which collates variables to pass to the template engine.
183
- #
184
- # @return [Hash]
185
- def get_variables(variables)
186
- {site: @configuration}.deep_merge!(metadata).deep_merge!(variables)
187
- end
188
- end
189
- end
data/lib/usmu/page.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'usmu/layout'
2
-
3
- module Usmu
4
- # Represents a page in the source directory of the website.
5
- class Page < Layout
6
- protected
7
-
8
- # @!attribute [r] content_path
9
- # @return [string] the base path to the files used by this class.
10
- #
11
- # Returns the base path to the files used by this class.
12
- #
13
- # This folder should be the parent folder for the file named by the name attribute.
14
- #
15
- # @see #name
16
- def content_path
17
- @configuration.source_path
18
- end
19
- end
20
- end