photish 0.1.6 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f389c011653a5f505b5da4ec206d127fad29b9c5
4
- data.tar.gz: f48fc53c2bdd720e105ac1d9cbccb18717f53825
3
+ metadata.gz: 4815953c918957b9276b9f71f6ad4e296a8c4120
4
+ data.tar.gz: 27900c1a28826e6e1c69ec35c4c67388b6638347
5
5
  SHA512:
6
- metadata.gz: 2e7461f3149ba958ddce657af522a08c1ce9a2aa98a5fbfbaaba4d398bc6769b920e55c610505586d48982ade9694e8a38ba44b2be6e2d980f01f2c84ea45e57
7
- data.tar.gz: 0cc7394c4dcafad97d03731c62fa61681d654de03b41e7508b60e0a942620c5d2526915b0cb4b14937519c2497f489072400fa13471a74f69a3d25f1816e6c02
6
+ metadata.gz: 8941c122835aed8ffc2dac6c0f0b1f3c1f6b286ec0c9a020df21c252db438a9c9905fe9ef2b5ae8382674abb35810aa95f23ec7038bf8f2a27f50b7026aed7ba
7
+ data.tar.gz: 953ba2db9319f21c7dee454c8ddb63da089838d36737c6c459f8c2313e099db5253bb63cb56aaaba9d2b82a8bd7b9a59205ae2da99dc2fc76adbdf89318d192b
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in photish.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'aruba', git: 'https://github.com/cucumber/aruba.git', ref: '0a3bffa'
8
+ end
data/README.md CHANGED
@@ -56,6 +56,7 @@ and running:
56
56
  - [Generate](#generate)
57
57
  - [Execution Order](#execution-order)
58
58
  - [Host](#host)
59
+ - [Rake Task](#rake-task)
59
60
  - [Development](#development)
60
61
  - [Contributing](#contributing)
61
62
  - [License](#license)
@@ -412,7 +413,29 @@ server to serve the HTML files:
412
413
 
413
414
  $ photish host
414
415
 
415
- The local version of your website will be visible at [http://localhost:9876/](http://localhost:9876/)
416
+ The local version of your website will be visible at
417
+ [http://localhost:9876/](http://localhost:9876/).
418
+
419
+ The Host command will also automatically regenerate the website on startup and
420
+ when a file is added, removed or modified in the `photo_dir` or `site_dir`.
421
+
422
+ ### Rake Task
423
+
424
+ If you would prefer to use Photish as a task in
425
+ [Rake](http://rake.rubyforge.org/). A helper class is available to create
426
+ custom rake tasks that call Photish. The helper class is defined in
427
+ [Photish::Rake::Task](https://github.com/henrylawson/photish/blob/master/lib/photish/rake/task.rb).
428
+
429
+ In your Rakefile, simply add the following to wrap the generate command:
430
+
431
+ ```ruby
432
+ Photish::Rake::Task.new(:generate, 'Compiles the project to HTML') do |t|
433
+ t.options = "generate"
434
+ end
435
+ ```
436
+
437
+ The above code will define a rake task called `generate` which can be ran
438
+ by using `rake generate`. It is the equivalent of `photish generate`.
416
439
 
417
440
  ## Development
418
441
 
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require 'cucumber'
4
4
  require 'cucumber/rake/task'
5
+ require 'photish/rake/task'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
@@ -9,4 +10,35 @@ Cucumber::Rake::Task.new(:features) do |t|
9
10
  t.cucumber_opts = "features --format pretty"
10
11
  end
11
12
 
12
- task :default => [:spec, :features]
13
+ desc 'Gather code climate results'
14
+ task :gather_coverage do
15
+ require 'simplecov'
16
+ require 'codeclimate-test-reporter'
17
+ CodeClimate::TestReporter::Formatter.new.format(SimpleCov.result)
18
+ end
19
+
20
+ desc 'Clean output folders'
21
+ task :clean do
22
+ FileUtils.rm_rf('coverage')
23
+ end
24
+
25
+ task :default => [:clean,
26
+ :spec,
27
+ :features,
28
+ :gather_coverage]
29
+
30
+ namespace :photish do
31
+ Photish::Rake::Task.new(:init, 'Creates a basic project') do |t|
32
+ t.options = "init"
33
+ end
34
+
35
+ Photish::Rake::Task.new(:generate, 'Generates all the code') do |t|
36
+ t.options = "generate"
37
+ end
38
+
39
+ Photish::Rake::Task.new(:host, 'Starts a HTTP and hosts the code') do |t|
40
+ t.options = "host"
41
+ end
42
+
43
+ task :all => [:init, :generate, :host]
44
+ end
data/TODO.md CHANGED
@@ -5,13 +5,13 @@
5
5
  ## Backlog
6
6
 
7
7
  1. Custom user created helpers in templates
8
- 1. RDoc documentation for classes
9
- 1. A Rakefile task for each of the commands
10
8
  1. A `deploy` command as a gem to deploy to github pages, netlify, amazon s3
11
- 1. Monitor for file changes and regenerate for `host` command
12
9
  1. URL customization, relative, absolute with or without hostname URLs (for
13
10
  different host envs)
11
+ 1. Custom template rendering outside of `_templates` folder
14
12
  1. Proper asset pipeline for CSS
15
- 1. Customer template rendering outside of `_templates` folder
16
- 1. A sitemap helper for use in custome templates for example `sitemap.xml`
13
+ 1. A sitemap helper plugin for use in custom templates for example
14
+ `sitemap.xml`
17
15
  1. Share on RubyWebToolkit, StaticGen, etc
16
+ 1. RDoc documentation for classes
17
+ 1. More intelligent regeneration based on changes
data/exe/photish CHANGED
@@ -1,4 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ if ENV['COVERAGE']
3
+ require 'simplecov'
4
+ require 'codeclimate-test-reporter'
2
5
 
3
- require 'photish/cli'
4
- Photish::CLI.start
6
+ SimpleCov.command_name "photish-binary-#{Process.pid}"
7
+ SimpleCov.root(File.join(File.expand_path(File.dirname(__FILE__)), '..'))
8
+ SimpleCov.start CodeClimate::TestReporter.configuration.profile
9
+ end
10
+
11
+ require 'photish/cli/interface'
12
+ Photish::CLI::Interface.start
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+ require 'photish/command/generate'
3
+ require 'photish/command/host'
4
+ require 'photish/command/init'
5
+
6
+ module Photish
7
+ module CLI
8
+ class Interface < Thor
9
+ package_name "Photish"
10
+
11
+ desc "generate", "Generates the gallery static site"
12
+ def generate
13
+ Photish::Command::Generate.new(options).execute
14
+ end
15
+
16
+ desc "host", "Serves the HTML on a HTTP server"
17
+ def host
18
+ Photish::Command::Host.new(options).execute
19
+ end
20
+
21
+ desc "init", "Creates a basic Photish site sctructure"
22
+ def init
23
+ Photish::Command::Init.new(options).execute
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -5,15 +5,14 @@ require 'photish/render/site'
5
5
 
6
6
  module Photish
7
7
  module Command
8
- class Generation
8
+ class Generate
9
9
  def initialize(runtime_config)
10
- @config = Photish::Config::AppSettings.new(runtime_config)
11
- .config
10
+ @runtime_config = runtime_config
12
11
  @log = Logging.logger[self]
13
12
  end
14
13
 
15
14
  def execute
16
- Photish::Log::Logger.setup_logging(config)
15
+ Photish::Log::Logger.instance.setup_logging(config)
17
16
 
18
17
  log_important_config_values
19
18
  log_album_and_photo_names
@@ -23,9 +22,14 @@ module Photish
23
22
 
24
23
  private
25
24
 
26
- attr_reader :config,
25
+ attr_reader :runtime_config,
27
26
  :log
28
27
 
28
+ def config
29
+ @config ||= Photish::Config::AppSettings.new(runtime_config)
30
+ .config
31
+ end
32
+
29
33
  def log_important_config_values
30
34
  log.info "Photo directory: #{photo_dir}"
31
35
  log.info "Site directory: #{site_dir}"
@@ -1,30 +1,44 @@
1
1
  require 'photish/log/logger'
2
2
  require 'photish/log/access_log'
3
3
  require 'webrick'
4
+ require 'listen'
4
5
 
5
6
  module Photish
6
7
  module Command
7
8
  class Host
8
9
  def initialize(runtime_config)
9
- @config = Photish::Config::AppSettings.new(runtime_config)
10
- .config
10
+ @runtime_config = runtime_config
11
11
  @log = Logging.logger[self]
12
12
  end
13
13
 
14
14
  def execute
15
- Photish::Log::Logger.setup_logging(config)
15
+ Photish::Log::Logger.instance.setup_logging(config)
16
16
 
17
- trap 'INT' do server.shutdown end
18
17
  log.info "Site will be running at http://0.0.0.0:#{port}/"
19
- server.start
20
- log.info "Site has been shutdown"
18
+ log.info "Monitoring paths #{paths_to_monitor}"
19
+
20
+ regenerate_entire_site
21
+ start_http_server_with_listener
21
22
  end
22
23
 
23
24
  private
24
25
 
25
- attr_reader :config,
26
+ attr_reader :runtime_config,
26
27
  :log
27
28
 
29
+ def start_http_server_with_listener
30
+ trap 'INT' do server.shutdown end
31
+ listener.start
32
+ server.start
33
+ listener.stop
34
+ log.info "Photish host has shutdown"
35
+ end
36
+
37
+ def config
38
+ @config ||= Photish::Config::AppSettings.new(runtime_config)
39
+ .config
40
+ end
41
+
28
42
  def server
29
43
  @server ||= WEBrick::HTTPServer.new(Port: port,
30
44
  DocumentRoot: output_dir,
@@ -32,6 +46,21 @@ module Photish
32
46
  Logger: log)
33
47
  end
34
48
 
49
+ def listener
50
+ @listener ||= Listen.to(*paths_to_monitor) do |modified, added, removed|
51
+ log.info "File was modified #{modified}" if modified.present?
52
+ log.info "File was added #{added}" if added.present?
53
+ log.info "File was removed #{removed}" if removed.present?
54
+
55
+ regenerate_entire_site
56
+ end
57
+ end
58
+
59
+ def paths_to_monitor
60
+ [site_dir,
61
+ photos_dir]
62
+ end
63
+
35
64
  def access_log
36
65
  [
37
66
  [Photish::Log::AccessLog.new,
@@ -39,6 +68,12 @@ module Photish
39
68
  ]
40
69
  end
41
70
 
71
+ def regenerate_entire_site
72
+ log.info "Regenerating site"
73
+ Photish::Command::Generate.new(runtime_config)
74
+ .execute
75
+ end
76
+
42
77
  def port
43
78
  config.val(:port)
44
79
  end
@@ -46,6 +81,14 @@ module Photish
46
81
  def output_dir
47
82
  config.val(:output_dir)
48
83
  end
84
+
85
+ def site_dir
86
+ config.val(:site_dir)
87
+ end
88
+
89
+ def photos_dir
90
+ config.val(:photo_dir)
91
+ end
49
92
  end
50
93
  end
51
94
  end
@@ -4,13 +4,12 @@ module Photish
4
4
  module Command
5
5
  class Init
6
6
  def initialize(runtime_config)
7
- @config = Photish::Config::AppSettings.new(runtime_config)
8
- .config
7
+ @runtime_config = runtime_config
9
8
  @log = Logging.logger[self]
10
9
  end
11
10
 
12
11
  def execute
13
- Photish::Log::Logger.setup_logging(config)
12
+ Photish::Log::Logger.instance.setup_logging(config)
14
13
 
15
14
  FileUtils.cp_r(config_file, Dir.pwd)
16
15
  FileUtils.cp_r(gitignore_file, File.join(Dir.pwd, '.gitignore'))
@@ -21,9 +20,14 @@ module Photish
21
20
 
22
21
  private
23
22
 
24
- attr_reader :config,
23
+ attr_reader :runtime_config,
25
24
  :log
26
25
 
26
+ def config
27
+ @config ||= Photish::Config::AppSettings.new(runtime_config)
28
+ .config
29
+ end
30
+
27
31
  def config_file
28
32
  asset_path('config.yml')
29
33
  end
@@ -6,7 +6,7 @@ module Photish
6
6
  module Breadcrumbable
7
7
  def breadcrumbs
8
8
  doc = Nokogiri::HTML::DocumentFragment.parse("")
9
- builder = Nokogiri::HTML::Builder.with(doc) do |doc|
9
+ Nokogiri::HTML::Builder.with(doc) do |doc|
10
10
  doc.ul(class: 'breadcrumbs') {
11
11
  parents_and_me.each_with_index do |level, index|
12
12
  doc.li(class: crumb_class(index)) {
@@ -2,64 +2,72 @@ require 'logging'
2
2
 
3
3
  module Photish
4
4
  module Log
5
- module Logger
6
- class << self
7
- def setup_logging(config)
8
- setup_color_scheme if colorize?(config)
9
- setup_stdout_output if output_to_stdout?(config)
10
- setup_file_output if output_to_file?(config)
5
+ class Logger
6
+ include Singleton
11
7
 
12
- Logging.logger.root.level = logging_level(config)
13
- end
8
+ attr_accessor :setup_complete
14
9
 
15
- private
10
+ def initialize
11
+ @setup_complete = false
12
+ end
13
+
14
+ def setup_logging(config)
15
+ return if setup_complete
16
+ setup_color_scheme if colorize?(config)
17
+ setup_stdout_output if output_to_stdout?(config)
18
+ setup_file_output if output_to_file?(config)
16
19
 
17
- def logging_level(config)
18
- config.val(:logging)[:level].to_sym
19
- end
20
+ Logging.logger.root.level = logging_level(config)
21
+ self.setup_complete = true
22
+ end
20
23
 
21
- def colorize?(config)
22
- config.val(:logging)[:colorize]
23
- end
24
+ private
24
25
 
25
- def output_to_stdout?(config)
26
- config.val(:logging)[:output].include?('stdout')
27
- end
26
+ def logging_level(config)
27
+ config.val(:logging)[:level].to_sym
28
+ end
28
29
 
29
- def output_to_file?(config)
30
- config.val(:logging)[:output].include?('file')
31
- end
30
+ def colorize?(config)
31
+ config.val(:logging)[:colorize]
32
+ end
32
33
 
33
- def setup_color_scheme
34
- Logging.color_scheme('bright',
35
- levels: {
36
- info: :green,
37
- warn: :yellow,
38
- error: :red,
39
- fatal: [:white, :on_red]
40
- },
41
- date: :blue,
42
- logger: :cyan,
43
- message: :magenta
44
- )
45
- end
34
+ def output_to_stdout?(config)
35
+ config.val(:logging)[:output].include?('stdout')
36
+ end
37
+
38
+ def output_to_file?(config)
39
+ config.val(:logging)[:output].include?('file')
40
+ end
46
41
 
47
- def setup_stdout_output
48
- Logging.appenders.stdout(
49
- 'stdout',
50
- layout: Logging.layouts.pattern(
51
- pattern: '[%d] %-5l %c: %m\n',
52
- color_scheme: 'bright'
53
- )
42
+ def setup_color_scheme
43
+ Logging.color_scheme('bright',
44
+ levels: {
45
+ info: :green,
46
+ warn: :yellow,
47
+ error: :red,
48
+ fatal: [:white, :on_red]
49
+ },
50
+ date: :blue,
51
+ logger: :cyan,
52
+ message: :magenta
53
+ )
54
+ end
55
+
56
+ def setup_stdout_output
57
+ Logging.appenders.stdout(
58
+ 'stdout',
59
+ layout: Logging.layouts.pattern(
60
+ pattern: '[%d] %-5l %c: %m\n',
61
+ color_scheme: 'bright'
54
62
  )
55
- Logging.logger.root.add_appenders('stdout')
56
- end
63
+ )
64
+ Logging.logger.root.add_appenders('stdout')
65
+ end
57
66
 
58
- def setup_file_output
59
- FileUtils.mkdir_p('log')
60
- file_appender = Logging.appenders.file('log/photish.log')
61
- Logging.logger.root.add_appenders(file_appender)
62
- end
67
+ def setup_file_output
68
+ FileUtils.mkdir_p('log')
69
+ file_appender = Logging.appenders.file('log/photish.log')
70
+ Logging.logger.root.add_appenders(file_appender)
63
71
  end
64
72
  end
65
73
  end
@@ -0,0 +1,32 @@
1
+ require 'photish/cli/interface'
2
+ require 'rake'
3
+
4
+ module Photish
5
+ module Rake
6
+ class Task
7
+ include ::Rake::DSL if defined?(::Rake::DSL)
8
+
9
+ attr_accessor :options
10
+
11
+ def initialize(task_name = "photish", desc = "Run photish")
12
+ @task_name = task_name
13
+ @desc = desc
14
+ yield self if block_given?
15
+ define_task
16
+ end
17
+
18
+ def options=(opts)
19
+ @options = String === opts ? opts.split(' ') : opts
20
+ end
21
+
22
+ private
23
+
24
+ def define_task
25
+ desc @desc
26
+ task @task_name do
27
+ Photish::CLI::Interface.start(options)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Photish
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/photish.gemspec CHANGED
@@ -33,12 +33,12 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "recursive-open-struct", "~> 0.6"
34
34
  spec.add_dependency "nokogiri", "~> 1.6"
35
35
  spec.add_dependency "logging", "~> 2.0"
36
+ spec.add_dependency "listen", "~> 3.0"
36
37
 
37
38
  spec.add_development_dependency "bundler", "~> 1.10"
38
39
  spec.add_development_dependency "rake", "~> 10.0"
39
40
  spec.add_development_dependency "rspec"
40
41
  spec.add_development_dependency "cucumber"
41
- spec.add_development_dependency "aruba"
42
42
  spec.add_development_dependency "pry"
43
43
  spec.add_development_dependency "retriable"
44
44
  spec.add_development_dependency "codeclimate-test-reporter"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Lawson
@@ -165,49 +165,49 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '2.0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: bundler
168
+ name: listen
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '1.10'
174
- type: :development
173
+ version: '3.0'
174
+ type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '1.10'
180
+ version: '3.0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: rake
182
+ name: bundler
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '10.0'
187
+ version: '1.10'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '10.0'
194
+ version: '1.10'
195
195
  - !ruby/object:Gem::Dependency
196
- name: rspec
196
+ name: rake
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: '10.0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ">="
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: '10.0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: cucumber
210
+ name: rspec
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - ">="
@@ -221,7 +221,7 @@ dependencies:
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  - !ruby/object:Gem::Dependency
224
- name: aruba
224
+ name: cucumber
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - ">="
@@ -334,8 +334,8 @@ files:
334
334
  - lib/photish/assets/site/custom.html
335
335
  - lib/photish/assets/site/images/crumbs.gif
336
336
  - lib/photish/assets/site/styles/basic.css
337
- - lib/photish/cli.rb
338
- - lib/photish/command/generation.rb
337
+ - lib/photish/cli/interface.rb
338
+ - lib/photish/command/generate.rb
339
339
  - lib/photish/command/host.rb
340
340
  - lib/photish/command/init.rb
341
341
  - lib/photish/config/app_settings.rb
@@ -353,6 +353,7 @@ files:
353
353
  - lib/photish/gallery/traits/urlable.rb
354
354
  - lib/photish/log/access_log.rb
355
355
  - lib/photish/log/logger.rb
356
+ - lib/photish/rake/task.rb
356
357
  - lib/photish/render/image_conversion.rb
357
358
  - lib/photish/render/page.rb
358
359
  - lib/photish/render/site.rb
data/lib/photish/cli.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'thor'
2
- require 'photish/command/generation'
3
- require 'photish/command/host'
4
- require 'photish/command/init'
5
-
6
- module Photish
7
- class CLI < Thor
8
- package_name "Photish"
9
-
10
- desc "generate", "Generates the gallery static site"
11
- def generate
12
- Command::Generation.new(options).execute
13
- end
14
-
15
- desc "host", "Serves the HTML on a HTTP server"
16
- def host
17
- Command::Host.new(options).execute
18
- end
19
-
20
- desc "init", "Creates a basic Photish site sctructure"
21
- def init
22
- Command::Init.new(options).execute
23
- end
24
- end
25
- end
26
-