photish 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4815953c918957b9276b9f71f6ad4e296a8c4120
4
- data.tar.gz: 27900c1a28826e6e1c69ec35c4c67388b6638347
3
+ metadata.gz: d39b760e4b3dd56a1feefd2aa4149d8e8f8f8b20
4
+ data.tar.gz: 721fc210a9c59c7bb43acbccedc3d2802bc9c3d5
5
5
  SHA512:
6
- metadata.gz: 8941c122835aed8ffc2dac6c0f0b1f3c1f6b286ec0c9a020df21c252db438a9c9905fe9ef2b5ae8382674abb35810aa95f23ec7038bf8f2a27f50b7026aed7ba
7
- data.tar.gz: 953ba2db9319f21c7dee454c8ddb63da089838d36737c6c459f8c2313e099db5253bb63cb56aaaba9d2b82a8bd7b9a59205ae2da99dc2fc76adbdf89318d192b
6
+ metadata.gz: 495b94ebf70ea1ed448cb4043382e3e6fe89778538c6a6640c453c595427fafba5cdd6e67b9f758d3fabe235b6b3a9dabd1664c462f0cee3f00f4c10b58c1a01
7
+ data.tar.gz: 07827e7468ba84db98ff8021a0828a38dc7e2cf94957cfd62da379944a1cf4c3f779361305992c775117ec74f022cbed80bbfa59fe10d660930111833d7a9cd5
data/.gitignore CHANGED
@@ -1,10 +1,10 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /lib/photish/assets/output
1
+ .bundle
2
+ .yardoc
3
+ Gemfile.lock
4
+ _yardoc
5
+ coverage
6
+ doc
7
+ pkg
8
+ spec/reports
9
+ tmp
10
+ lib/photish/assets/output
data/README.md CHANGED
@@ -53,10 +53,14 @@ and running:
53
53
  - [Collection Template](#collection-template)
54
54
  - [Album Template](#album-template)
55
55
  - [Photo Template](#photo-template)
56
+ - [Template Helpers](#template-helpers)
56
57
  - [Generate](#generate)
57
58
  - [Execution Order](#execution-order)
58
59
  - [Host](#host)
59
60
  - [Rake Task](#rake-task)
61
+ - [Plugins](#plugins)
62
+ - [Template Helper Plugins](#template-helper-plugins)
63
+ - [Plugin Loading](#plugin-loading)
60
64
  - [Development](#development)
61
65
  - [Contributing](#contributing)
62
66
  - [License](#license)
@@ -381,6 +385,48 @@ metadata | an object with methods for the attributes in the `{photo_n
381
385
  exif | an object with methods for the exif data of the original photo file
382
386
  images | an array of all the [Images](https://github.com/henrylawson/photish/blob/master/lib/photish/gallery/image.rb) for this photo, an Image will be a version of the photo in the quality configured in `config.yml`
383
387
 
388
+ #### Template Helpers
389
+
390
+ A template helper is a simple method that is available in the template that can
391
+ be called to render complex information.
392
+
393
+ For example in a template, the method `breadcrumbs` can be called:
394
+
395
+ ```slim
396
+ div.content
397
+ div.site-breadcrumbs
398
+ == breadcrumbs
399
+ ```
400
+
401
+ When rendered this will result in an unordered list of pages above the
402
+ current page in the hierarchy:
403
+
404
+ ```html
405
+ <div class="content">
406
+ <div class="site-breadcrumbs">
407
+ <ul class="breadcrumbs">
408
+ <li class="breadcrumb crumb-0 crumb-first">
409
+ <a href="/index.html">Home</a>
410
+ </li>
411
+ <li class="breadcrumb crumb-1">
412
+ <a href="/big-dogs/index.html">Big Dogs</a>
413
+ </li>
414
+ <li class="breadcrumb crumb-2 crumb-last">
415
+ <a href="/big-dogs/tired-dogs/index.html">Tired Dogs</a>
416
+ </li>
417
+ </ul>
418
+ </div>
419
+ </div>
420
+ ```
421
+
422
+ Custom template helpers are supported through [Plugins](#plugins).
423
+
424
+ By default, Photish comes with the following helpers:
425
+
426
+ Method | Description
427
+ ----------- | -----------
428
+ breadcrumbs | an unordered list of pages above the current page in the hierarchy
429
+
384
430
  ### Generate
385
431
 
386
432
  The static HTML can be generated by running the below command inside the
@@ -437,6 +483,58 @@ end
437
483
  The above code will define a rake task called `generate` which can be ran
438
484
  by using `rake generate`. It is the equivalent of `photish generate`.
439
485
 
486
+ ### Plugins
487
+
488
+ Photish supports extension through the creation of plugins.
489
+
490
+ #### Template Helper Plugins
491
+
492
+ To create a template helper plugin you must:
493
+
494
+ 1. Create a module in the `Photish:Plugin` module namespace
495
+ 1. Implement the `self.is_for?(type)` method
496
+ 1. Implement your custom helper method(s)
497
+
498
+ A simple plugin is bellow, this plugin is for all [Photo
499
+ Template](#photo-template)'s as the `self.is_for?(type)` method only returns
500
+ true for `Photish::Plugin::Type::Photo` types. When the `shout` method is
501
+ called inside the template, it will render the message in bold wrapped in the
502
+ "I am shouting" text.
503
+
504
+ **site/_plugins/shout.rb**
505
+ ```ruby
506
+ require 'nokogiri'
507
+
508
+ module Photish::Plugin::Shout
509
+
510
+ def self.is_for?(type)
511
+ Photish::Plugin::Type::Photo == type
512
+ end
513
+
514
+ def shout(message)
515
+ "<strong>I am shouting '#{message}'!!!</strong>"
516
+ end
517
+ end
518
+ ```
519
+
520
+ If the above code is saved to `site/_plugins/shout.rb` Photish will detect the
521
+ plugin ruby file at runtime and it will load and make the method available in
522
+ the template.
523
+
524
+ A usage example is below
525
+
526
+ **site/_templates/photo.slim**
527
+ ```slim
528
+ div.my-shouting-content
529
+ == shout("HELLO")
530
+ ```
531
+
532
+ ### Plugin Loading
533
+
534
+ All ruby files in `site/_plugins` will be loaded into the runtime but only
535
+ those in the `Photish::Plugin` namespace with a `self.is_for?(type)` method
536
+ will be used by Photish as plugins.
537
+
440
538
  ## Development
441
539
 
442
540
  If you would like to contribute to Photish by creating a new feature or fixing
data/TODO.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  ## In Progress
4
4
 
5
- ## Backlog
6
-
7
- 1. Custom user created helpers in templates
8
5
  1. A `deploy` command as a gem to deploy to github pages, netlify, amazon s3
9
6
  1. URL customization, relative, absolute with or without hostname URLs (for
10
7
  different host envs)
11
- 1. Custom template rendering outside of `_templates` folder
8
+
9
+ ## Backlog
10
+
11
+ 1. Custom template rendering outside of `_templates` folder using `page.{type}`
12
12
  1. Proper asset pipeline for CSS
13
13
  1. A sitemap helper plugin for use in custom templates for example
14
14
  `sitemap.xml`
@@ -0,0 +1,22 @@
1
+ require 'nokogiri'
2
+
3
+ module Photish::Plugin::YellLoud
4
+
5
+ def self.is_for?(type)
6
+ [
7
+ Photish::Plugin::Type::Collection,
8
+ Photish::Plugin::Type::Album,
9
+ Photish::Plugin::Type::Photo,
10
+ Photish::Plugin::Type::Image
11
+ ].include?(type)
12
+ end
13
+
14
+ def yell_very_loud
15
+ doc = Nokogiri::HTML::DocumentFragment.parse("")
16
+ Nokogiri::HTML::Builder.with(doc) do |doc|
17
+ doc.span("Yelling \"#{name}\" from a plugin!",
18
+ style: 'font-weight:bold;color:red;font-size:200%;')
19
+ end
20
+ doc.to_html
21
+ end
22
+ end
@@ -1,7 +1,7 @@
1
1
  div.album
2
2
  div.album-title
3
3
  a href=url
4
- | #{name}
4
+ == yell_very_loud
5
5
  - if metadata.try(:description)
6
6
  div.album-blurb
7
7
  p #{metadata.try(:description)}
@@ -16,6 +16,7 @@ module Photish
16
16
 
17
17
  log_important_config_values
18
18
  log_album_and_photo_names
19
+ load_all_plugins
19
20
  render_whole_site
20
21
  log.info 'Site generation completed successfully'
21
22
  end
@@ -25,6 +26,16 @@ module Photish
25
26
  attr_reader :runtime_config,
26
27
  :log
27
28
 
29
+ def load_all_plugins
30
+ Dir[File.join(site_dir, '_plugins', '*.rb')].each do |file|
31
+ require file
32
+ end
33
+
34
+ Photish::Plugin::Repository.all_plugins.each do |plugin|
35
+ log.info "Found plugin #{plugin}"
36
+ end
37
+ end
38
+
28
39
  def config
29
40
  @config ||= Photish::Config::AppSettings.new(runtime_config)
30
41
  .config
@@ -3,6 +3,7 @@ require 'photish/gallery/traits/urlable'
3
3
  require 'photish/gallery/traits/albumable'
4
4
  require 'photish/gallery/traits/metadatable'
5
5
  require 'photish/gallery/traits/breadcrumbable'
6
+ require 'photish/plugin/pluginable'
6
7
  require 'active_support'
7
8
  require 'active_support/core_ext'
8
9
  require 'filemagic'
@@ -10,14 +11,16 @@ require 'filemagic'
10
11
  module Photish
11
12
  module Gallery
12
13
  class Album
13
- include ::Photish::Gallery::Traits::Urlable
14
- include ::Photish::Gallery::Traits::Albumable
15
- include ::Photish::Gallery::Traits::Metadatable
16
- include ::Photish::Gallery::Traits::Breadcrumbable
14
+ include Photish::Gallery::Traits::Urlable
15
+ include Photish::Gallery::Traits::Albumable
16
+ include Photish::Gallery::Traits::Metadatable
17
+ include Photish::Gallery::Traits::Breadcrumbable
18
+ include Photish::Plugin::Pluginable
17
19
 
18
20
  delegate :qualities, to: :parent, allow_nil: true
19
21
 
20
22
  def initialize(parent, path)
23
+ super
21
24
  @parent = parent
22
25
  @path = path
23
26
  end
@@ -35,6 +38,10 @@ module Photish
35
38
  .map { |file| Photo.new(self, file) }
36
39
  end
37
40
 
41
+ def plugin_type
42
+ Photish::Plugin::Type::Album
43
+ end
44
+
38
45
  private
39
46
 
40
47
  attr_reader :path,
@@ -2,18 +2,21 @@ require 'photish/gallery/album'
2
2
  require 'photish/gallery/traits/albumable'
3
3
  require 'photish/gallery/traits/metadatable'
4
4
  require 'photish/gallery/traits/breadcrumbable'
5
+ require 'photish/plugin/pluginable'
5
6
 
6
7
  module Photish
7
8
  module Gallery
8
9
  class Collection
9
- include ::Photish::Gallery::Traits::Urlable
10
- include ::Photish::Gallery::Traits::Albumable
11
- include ::Photish::Gallery::Traits::Metadatable
12
- include ::Photish::Gallery::Traits::Breadcrumbable
10
+ include Photish::Gallery::Traits::Urlable
11
+ include Photish::Gallery::Traits::Albumable
12
+ include Photish::Gallery::Traits::Metadatable
13
+ include Photish::Gallery::Traits::Breadcrumbable
14
+ include Photish::Plugin::Pluginable
13
15
 
14
16
  attr_reader :qualities
15
17
 
16
18
  def initialize(path, qualities)
19
+ super
17
20
  @path = path
18
21
  @qualities = qualities
19
22
  end
@@ -26,6 +29,10 @@ module Photish
26
29
  []
27
30
  end
28
31
 
32
+ def plugin_type
33
+ Photish::Plugin::Type::Collection
34
+ end
35
+
29
36
  private
30
37
 
31
38
  attr_reader :path
@@ -1,10 +1,12 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
+ require 'photish/plugin/pluginable'
3
4
 
4
5
  module Photish
5
6
  module Gallery
6
7
  class Image
7
- include ::Photish::Gallery::Traits::Urlable
8
+ include Photish::Gallery::Traits::Urlable
9
+ include Photish::Plugin::Pluginable
8
10
 
9
11
  delegate :name,
10
12
  :params,
@@ -13,6 +15,7 @@ module Photish
13
15
  attr_reader :path
14
16
 
15
17
  def initialize(parent, path, quality)
18
+ super
16
19
  @parent = parent
17
20
  @path = path
18
21
  @quality = quality
@@ -22,6 +25,10 @@ module Photish
22
25
  @name ||= "#{basename} #{quality_name}"
23
26
  end
24
27
 
28
+ def plugin_type
29
+ Photish::Plugin::Type::Image
30
+ end
31
+
25
32
  private
26
33
 
27
34
  attr_reader :parent,
@@ -2,6 +2,7 @@ require 'photish/gallery/traits/urlable'
2
2
  require 'photish/gallery/traits/metadatable'
3
3
  require 'photish/gallery/traits/breadcrumbable'
4
4
  require 'photish/gallery/image'
5
+ require 'photish/plugin/pluginable'
5
6
  require 'active_support'
6
7
  require 'active_support/core_ext'
7
8
  require 'mini_exiftool'
@@ -9,13 +10,15 @@ require 'mini_exiftool'
9
10
  module Photish
10
11
  module Gallery
11
12
  class Photo
12
- include ::Photish::Gallery::Traits::Urlable
13
- include ::Photish::Gallery::Traits::Metadatable
14
- include ::Photish::Gallery::Traits::Breadcrumbable
13
+ include Photish::Gallery::Traits::Urlable
14
+ include Photish::Gallery::Traits::Metadatable
15
+ include Photish::Gallery::Traits::Breadcrumbable
16
+ include Photish::Plugin::Pluginable
15
17
 
16
18
  delegate :qualities, to: :parent, allow_nil: true
17
19
 
18
20
  def initialize(parent, path)
21
+ super
19
22
  @parent = parent
20
23
  @path = path
21
24
  end
@@ -32,6 +35,10 @@ module Photish
32
35
  MiniExiftool.new(path)
33
36
  end
34
37
 
38
+ def plugin_type
39
+ Photish::Plugin::Type::Photo
40
+ end
41
+
35
42
  private
36
43
 
37
44
  attr_reader :path,
@@ -0,0 +1,14 @@
1
+ require 'photish/plugin/type'
2
+ require 'photish/plugin/repository'
3
+
4
+ module Photish
5
+ module Plugin
6
+ module Pluginable
7
+ def initialize(*_args)
8
+ Photish::Plugin::Repository.plugins_for(self.plugin_type).each do |moduol|
9
+ self.class.send(:include, moduol)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module Photish
3
+ module Plugin
4
+ module Repository
5
+ class << self
6
+ def plugins_for(type)
7
+ all_plugins.reject { |m| !m.is_for?(type) }
8
+ end
9
+
10
+ def all_plugins
11
+ Photish::Plugin.constants.map { |m| constantize(m) }
12
+ .reject { |m| ignored_modules.include?(m) }
13
+ end
14
+
15
+ private
16
+
17
+ def ignored_modules
18
+ [Photish::Plugin::Repository,
19
+ Photish::Plugin::Pluginable,
20
+ Photish::Plugin::Type]
21
+ end
22
+
23
+ def constantize(symbol)
24
+ Kernel.const_get("Photish::Plugin::#{symbol}")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ module Photish
2
+ module Plugin
3
+ module Type
4
+ module Collection; end
5
+ module Album; end
6
+ module Photo; end
7
+ module Image; end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Photish
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Lawson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-27 00:00:00.000000000 Z
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -327,6 +327,7 @@ files:
327
327
  - lib/photish/assets/photos/Small Dogs/Sleepy Dog.jpg
328
328
  - lib/photish/assets/photos/Small Dogs/Sleepy Dog.yml
329
329
  - lib/photish/assets/photos/Small Dogs/Squishy Dogs/Big Ear Dog.jpg
330
+ - lib/photish/assets/site/_plugins/yell_loud.rb
330
331
  - lib/photish/assets/site/_templates/album.slim
331
332
  - lib/photish/assets/site/_templates/collection.slim
332
333
  - lib/photish/assets/site/_templates/layout.slim
@@ -353,6 +354,9 @@ files:
353
354
  - lib/photish/gallery/traits/urlable.rb
354
355
  - lib/photish/log/access_log.rb
355
356
  - lib/photish/log/logger.rb
357
+ - lib/photish/plugin/pluginable.rb
358
+ - lib/photish/plugin/repository.rb
359
+ - lib/photish/plugin/type.rb
356
360
  - lib/photish/rake/task.rb
357
361
  - lib/photish/render/image_conversion.rb
358
362
  - lib/photish/render/page.rb