photish 0.1.5 → 0.1.6

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: 277dfe161a294df87082b4dd77c7f2d0da7a2b4d
4
- data.tar.gz: 368345cfd9d277260840b2c3df17db71dfd491c2
3
+ metadata.gz: f389c011653a5f505b5da4ec206d127fad29b9c5
4
+ data.tar.gz: f48fc53c2bdd720e105ac1d9cbccb18717f53825
5
5
  SHA512:
6
- metadata.gz: 0faabb7a8ba4dfc28a6d19dd17bf042e80dbde32d1a11b28401b6376d60c09a342466cb69f2fc223368f4ce6e01a8c88bfc8baafeabd3c44e3ac41ced080dea0
7
- data.tar.gz: 6d086c3276c64e4d44b34d1cc42d804ff2b30cb2428c7992bd8957050be48e1d99899acd79a1bf84518e3f09cd4688b4cecf48efd0e9160b1ef3bf55934fdb87
6
+ metadata.gz: 2e7461f3149ba958ddce657af522a08c1ce9a2aa98a5fbfbaaba4d398bc6769b920e55c610505586d48982ade9694e8a38ba44b2be6e2d980f01f2c84ea45e57
7
+ data.tar.gz: 0cc7394c4dcafad97d03731c62fa61681d654de03b41e7508b60e0a942620c5d2526915b0cb4b14937519c2497f489072400fa13471a74f69a3d25f1816e6c02
data/README.md CHANGED
@@ -255,7 +255,7 @@ generated file, the generated file will clobber the asset.
255
255
 
256
256
  #### Config File Options
257
257
 
258
- Below is a basic `config.yml` file:
258
+ Below is a complete `config.yml` file:
259
259
 
260
260
  ```yaml
261
261
  port: 9876
@@ -269,6 +269,10 @@ templates:
269
269
  collection: collection.slim
270
270
  album: album.slim
271
271
  photo: photo.slim
272
+ logging:
273
+ colorize: true
274
+ level: 'info'
275
+ output: ['stdout', 'file']
272
276
  ```
273
277
 
274
278
  The meanings and purpose of each field is defined below:
@@ -284,6 +288,10 @@ Field | Purpose
284
288
  `templates/collection` | the collection template file in the `site/_templates` folder
285
289
  `templates/album` | the album template file in the `site/_templates` folder
286
290
  `templates/photo` | the photo template file in the `site/_templates` folder
291
+ `logging` | a listing of the various logging options
292
+ `logging/colorize` | when outputting to `STDOUT`, `true` to use color, `false` for none
293
+ `logging/level` | the default logging level, it is advised to keep this at `info`
294
+ `logging/output` | the appenders for the logger, `stdout` goes to `STDOUT`, `file` goes to `log/photish.log`
287
295
 
288
296
  #### Customizing Templates
289
297
 
data/TODO.md CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  ## In Progress
4
4
 
5
- 1. A .gitignore file for the `init` project
6
- 1. Change logging to colorize on command options
7
- 1. Pipe WEBrick logging to log module
8
-
9
5
  ## Backlog
10
6
 
11
7
  1. Custom user created helpers in templates
@@ -10,3 +10,7 @@ templates:
10
10
  collection: collection.slim
11
11
  album: album.slim
12
12
  photo: photo.slim
13
+ logging:
14
+ colorize: true
15
+ level: 'info'
16
+ output: ['stdout', 'file']
@@ -0,0 +1,2 @@
1
+ output
2
+ log
@@ -12,7 +12,7 @@ module Photish
12
12
  Command::Generation.new(options).execute
13
13
  end
14
14
 
15
- desc "host", "Serves the HTML on a HTTP server at http://localhost:9876/"
15
+ desc "host", "Serves the HTML on a HTTP server"
16
16
  def host
17
17
  Command::Host.new(options).execute
18
18
  end
@@ -6,34 +6,36 @@ require 'photish/render/site'
6
6
  module Photish
7
7
  module Command
8
8
  class Generation
9
- include ::Photish::Log::Logger
10
-
11
9
  def initialize(runtime_config)
12
10
  @config = Photish::Config::AppSettings.new(runtime_config)
13
11
  .config
12
+ @log = Logging.logger[self]
14
13
  end
15
14
 
16
15
  def execute
16
+ Photish::Log::Logger.setup_logging(config)
17
+
17
18
  log_important_config_values
18
19
  log_album_and_photo_names
19
20
  render_whole_site
20
- log 'Site generation completed successfully'
21
+ log.info 'Site generation completed successfully'
21
22
  end
22
23
 
23
24
  private
24
25
 
25
- attr_reader :config
26
+ attr_reader :config,
27
+ :log
26
28
 
27
29
  def log_important_config_values
28
- log "Photo directory: #{photo_dir}"
29
- log "Site directory: #{site_dir}"
30
- log "Output directory: #{output_dir}"
30
+ log.info "Photo directory: #{photo_dir}"
31
+ log.info "Site directory: #{site_dir}"
32
+ log.info "Output directory: #{output_dir}"
31
33
  end
32
34
 
33
35
  def log_album_and_photo_names
34
36
  collection.albums.each do |album|
35
- log album.name
36
- log album.photos.map(&:name)
37
+ log.info album.name
38
+ log.info album.photos.map(&:name)
37
39
  end
38
40
  end
39
41
 
@@ -1,30 +1,42 @@
1
1
  require 'photish/log/logger'
2
+ require 'photish/log/access_log'
2
3
  require 'webrick'
3
4
 
4
5
  module Photish
5
6
  module Command
6
7
  class Host
7
- include ::Photish::Log::Logger
8
-
9
8
  def initialize(runtime_config)
10
9
  @config = Photish::Config::AppSettings.new(runtime_config)
11
10
  .config
11
+ @log = Logging.logger[self]
12
12
  end
13
13
 
14
14
  def execute
15
+ Photish::Log::Logger.setup_logging(config)
16
+
15
17
  trap 'INT' do server.shutdown end
16
- log "Site will be running at http://0.0.0.0:#{port}/"
18
+ log.info "Site will be running at http://0.0.0.0:#{port}/"
17
19
  server.start
18
- log "Site has been shutdown"
20
+ log.info "Site has been shutdown"
19
21
  end
20
22
 
21
23
  private
22
24
 
23
- attr_reader :config
25
+ attr_reader :config,
26
+ :log
24
27
 
25
28
  def server
26
- @server ||= WEBrick::HTTPServer.new(Port: port,
27
- DocumentRoot: output_dir)
29
+ @server ||= WEBrick::HTTPServer.new(Port: port,
30
+ DocumentRoot: output_dir,
31
+ AccessLog: access_log,
32
+ Logger: log)
33
+ end
34
+
35
+ def access_log
36
+ [
37
+ [Photish::Log::AccessLog.new,
38
+ WEBrick::AccessLog::COMBINED_LOG_FORMAT]
39
+ ]
28
40
  end
29
41
 
30
42
  def port
@@ -3,27 +3,35 @@ require 'photish/log/logger'
3
3
  module Photish
4
4
  module Command
5
5
  class Init
6
- include ::Photish::Log::Logger
7
-
8
6
  def initialize(runtime_config)
9
- @runtime_config = runtime_config
7
+ @config = Photish::Config::AppSettings.new(runtime_config)
8
+ .config
9
+ @log = Logging.logger[self]
10
10
  end
11
11
 
12
12
  def execute
13
+ Photish::Log::Logger.setup_logging(config)
14
+
13
15
  FileUtils.cp_r(config_file, Dir.pwd)
16
+ FileUtils.cp_r(gitignore_file, File.join(Dir.pwd, '.gitignore'))
14
17
  FileUtils.cp_r(photos_dir, Dir.pwd)
15
18
  FileUtils.cp_r(site_dir, Dir.pwd)
16
- log "Photish site initiated successfully"
19
+ log.info "Photish site initiated successfully"
17
20
  end
18
21
 
19
22
  private
20
23
 
21
- attr_reader :runtime_config
24
+ attr_reader :config,
25
+ :log
22
26
 
23
27
  def config_file
24
28
  asset_path('config.yml')
25
29
  end
26
30
 
31
+ def gitignore_file
32
+ asset_path('gitignore')
33
+ end
34
+
27
35
  def photos_dir
28
36
  asset_path('photos')
29
37
  end
@@ -18,6 +18,11 @@ module Photish
18
18
  collection: 'collection.slim',
19
19
  album: 'album.slim',
20
20
  photo: 'photo.slim'
21
+ },
22
+ logging: {
23
+ colorize: true,
24
+ output: ['stdout', 'file'],
25
+ level: 'info'
21
26
  }
22
27
  }
23
28
  end
@@ -8,7 +8,8 @@ module Photish
8
8
  end
9
9
 
10
10
  def hash
11
- @hash ||= YAML.load_file(config_file_path)
11
+ return {} if !File.exist?(config_file_path)
12
+ YAML.load_file(config_file_path)
12
13
  end
13
14
 
14
15
  private
@@ -8,23 +8,13 @@ module Photish
8
8
  end
9
9
 
10
10
  def path
11
- ensure_expected_path_exists
12
- expected_path
11
+ File.join(directory, config_file_name)
13
12
  end
14
13
 
15
14
  private
16
15
 
17
16
  attr_reader :site_dir
18
17
 
19
- def ensure_expected_path_exists
20
- return if File.exist?(expected_path)
21
- raise "Config file does not exist at #{expected_path}"
22
- end
23
-
24
- def expected_path
25
- File.join(directory, config_file_name)
26
- end
27
-
28
18
  def directory
29
19
  site_dir || Dir.pwd
30
20
  end
@@ -10,7 +10,6 @@ require 'filemagic'
10
10
  module Photish
11
11
  module Gallery
12
12
  class Album
13
-
14
13
  include ::Photish::Gallery::Traits::Urlable
15
14
  include ::Photish::Gallery::Traits::Albumable
16
15
  include ::Photish::Gallery::Traits::Metadatable
@@ -6,7 +6,6 @@ require 'photish/gallery/traits/breadcrumbable'
6
6
  module Photish
7
7
  module Gallery
8
8
  class Collection
9
-
10
9
  include ::Photish::Gallery::Traits::Urlable
11
10
  include ::Photish::Gallery::Traits::Albumable
12
11
  include ::Photish::Gallery::Traits::Metadatable
@@ -4,7 +4,6 @@ require 'active_support/core_ext'
4
4
  module Photish
5
5
  module Gallery
6
6
  class Image
7
-
8
7
  include ::Photish::Gallery::Traits::Urlable
9
8
 
10
9
  delegate :name,
@@ -9,7 +9,6 @@ require 'mini_exiftool'
9
9
  module Photish
10
10
  module Gallery
11
11
  class Photo
12
-
13
12
  include ::Photish::Gallery::Traits::Urlable
14
13
  include ::Photish::Gallery::Traits::Metadatable
15
14
  include ::Photish::Gallery::Traits::Breadcrumbable
@@ -0,0 +1,17 @@
1
+ module Photish
2
+ module Log
3
+ class AccessLog
4
+ def initialize
5
+ @log = Logging.logger[self]
6
+ end
7
+
8
+ def <<(message)
9
+ log.info message.chomp
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :log
15
+ end
16
+ end
17
+ end
@@ -1,10 +1,65 @@
1
- require 'colorize'
1
+ require 'logging'
2
2
 
3
3
  module Photish
4
4
  module Log
5
5
  module Logger
6
- def log(message)
7
- puts "#{Time.now.iso8601.colorize(:blue)} => #{message.to_s.colorize(:green)}"
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)
11
+
12
+ Logging.logger.root.level = logging_level(config)
13
+ end
14
+
15
+ private
16
+
17
+ def logging_level(config)
18
+ config.val(:logging)[:level].to_sym
19
+ end
20
+
21
+ def colorize?(config)
22
+ config.val(:logging)[:colorize]
23
+ end
24
+
25
+ def output_to_stdout?(config)
26
+ config.val(:logging)[:output].include?('stdout')
27
+ end
28
+
29
+ def output_to_file?(config)
30
+ config.val(:logging)[:output].include?('file')
31
+ end
32
+
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
46
+
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
+ )
54
+ )
55
+ Logging.logger.root.add_appenders('stdout')
56
+ end
57
+
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
8
63
  end
9
64
  end
10
65
  end
@@ -3,11 +3,9 @@ require 'mini_magick'
3
3
  module Photish
4
4
  module Render
5
5
  class ImageConversion
6
-
7
- include Photish::Log::Logger
8
-
9
6
  def initialize(output_dir)
10
7
  @output_dir = output_dir
8
+ @log = Logging.logger[self]
11
9
  end
12
10
 
13
11
  def render(images)
@@ -19,14 +17,15 @@ module Photish
19
17
  convert << image.path
20
18
  convert.merge!(image.quality_params)
21
19
  convert << output_file
22
- log "Performing image conversion #{convert.command}"
20
+ log.info "Performing image conversion #{convert.command}"
23
21
  end
24
22
  end
25
23
  end
26
24
 
27
25
  private
28
26
 
29
- attr_reader :output_dir
27
+ attr_reader :output_dir,
28
+ :log
30
29
  end
31
30
  end
32
31
  end
@@ -3,13 +3,11 @@ require 'tilt'
3
3
  module Photish
4
4
  module Render
5
5
  class Page
6
-
7
- include Photish::Log::Logger
8
-
9
6
  def initialize(layout_file, template_file, output_dir)
10
7
  @layout_file = layout_file
11
8
  @template_file = template_file
12
9
  @output_dir = output_dir
10
+ @log = Logging.logger[self]
13
11
  end
14
12
 
15
13
  def render(models)
@@ -18,7 +16,7 @@ module Photish
18
16
  output_model_file = relative_to_output_dir(model.url_parts)
19
17
  output_model_dir = relative_to_output_dir(model.base_url_parts)
20
18
 
21
- log "Rendering #{model.url} with template #{template_file} to #{output_model_file}"
19
+ log.info "Rendering #{model.url} with template #{template_file} to #{output_model_file}"
22
20
 
23
21
  FileUtils.mkdir_p(output_model_dir)
24
22
  File.write(output_model_file, rendered_model)
@@ -29,7 +27,8 @@ module Photish
29
27
 
30
28
  attr_reader :template_file,
31
29
  :layout_file,
32
- :output_dir
30
+ :output_dir,
31
+ :log
33
32
 
34
33
  def relative_to_output_dir(url_parts)
35
34
  File.join(output_dir, url_parts)
@@ -1,3 +1,3 @@
1
1
  module Photish
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "anemone", "~> 0.7"
32
32
  spec.add_dependency "mini_exiftool", "~> 2.5"
33
33
  spec.add_dependency "recursive-open-struct", "~> 0.6"
34
- spec.add_dependency "colorize", "~> 0.7"
35
34
  spec.add_dependency "nokogiri", "~> 1.6"
35
+ spec.add_dependency "logging", "~> 2.0"
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 1.10"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
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.5
4
+ version: 0.1.6
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-25 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -137,33 +137,33 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.6'
139
139
  - !ruby/object:Gem::Dependency
140
- name: colorize
140
+ name: nokogiri
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.7'
145
+ version: '1.6'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0.7'
152
+ version: '1.6'
153
153
  - !ruby/object:Gem::Dependency
154
- name: nokogiri
154
+ name: logging
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.6'
159
+ version: '2.0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.6'
166
+ version: '2.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: bundler
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -317,6 +317,7 @@ files:
317
317
  - exe/photish
318
318
  - lib/photish.rb
319
319
  - lib/photish/assets/config.yml
320
+ - lib/photish/assets/gitignore
320
321
  - lib/photish/assets/photos/Big Dogs/Tired Dogs.jpg
321
322
  - lib/photish/assets/photos/Big Dogs/Winking Dog.jpg
322
323
  - lib/photish/assets/photos/Small Dogs/Fluffy Dogs/Exhausted Dogs.jpg
@@ -350,6 +351,7 @@ files:
350
351
  - lib/photish/gallery/traits/breadcrumbable.rb
351
352
  - lib/photish/gallery/traits/metadatable.rb
352
353
  - lib/photish/gallery/traits/urlable.rb
354
+ - lib/photish/log/access_log.rb
353
355
  - lib/photish/log/logger.rb
354
356
  - lib/photish/render/image_conversion.rb
355
357
  - lib/photish/render/page.rb