troy 0.0.35 → 0.0.36

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
  SHA256:
3
- metadata.gz: 1de66b8776191039502385cfc1ca3453f4b9bc30ae81b0eefbc4a7257124ad30
4
- data.tar.gz: 51fd07dbf2caac206263ed83fd0830d31f2326e30c3cec82796dcc578470d116
3
+ metadata.gz: 04b065e86e12781d992f5f023ff7aa6ca2595739841b9d96245d4ed76e5282b2
4
+ data.tar.gz: b2cff9bf95dc780b1a18a2de12a2dde3e756eb8b9e079027d8447039625472d0
5
5
  SHA512:
6
- metadata.gz: 7c79d4c7ffc7976d1e7624e8432bcc450b178f45ae46ee06e896a5a501f60e0ca0eec0273853fe304e83e6ef245733e9856a3588453e46571130099c1cb07bda
7
- data.tar.gz: 0d87cd79c7ef8e7be0383e5f6ff67788e06a9d3074c2d82e5e66a4ae20e2c26c259e268cbcd9c1fd0c9af740aa4fdb4be507d889f4b90a6652fc9eee97cc9010
6
+ metadata.gz: 8a0d318f8aa044bf7b6feef04ba2e613e5fc8bfd63cd4c29f247617cefbb8d4f3a7b084a29bbbd0f416e0b5604320da31036d82bb20ae5b225303bd5ac04166a
7
+ data.tar.gz: a0a1c0bb7658e7c92f8f98c086421ca83a00af30ba1f7a4c9aaa900549a580421f98f1f10298457d2f021d04213443adf09e5faea85983188022a313bd7c9844
@@ -0,0 +1,83 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Rails/Delegate:
8
+ Enabled: false
9
+
10
+ Style/StringLiterals:
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/SpaceInsideBlockBraces:
14
+ EnforcedStyle: space
15
+ EnforcedStyleForEmptyBraces: space
16
+ SpaceBeforeBlockParameters: false
17
+
18
+ Layout/SpaceInsideHashLiteralBraces:
19
+ EnforcedStyle: no_space
20
+ EnforcedStyleForEmptyBraces: no_space
21
+
22
+ Layout/FirstArrayElementLineBreak:
23
+ Enabled: true
24
+
25
+ Layout/FirstHashElementLineBreak:
26
+ Enabled: true
27
+
28
+ Style/SymbolArray:
29
+ Enabled: true
30
+
31
+ Style/PercentLiteralDelimiters:
32
+ PreferredDelimiters:
33
+ "%": "[]"
34
+ "%i": "[]"
35
+ "%q": "[]"
36
+ "%Q": "[]"
37
+ "%r": "{}"
38
+ "%s": "[]"
39
+ "%w": "[]"
40
+ "%W": "[]"
41
+ "%x": "[]"
42
+
43
+ Metrics/LineLength:
44
+ Enabled: true
45
+
46
+ Metrics/MethodLength:
47
+ Exclude:
48
+ - db/migrate/**.rb
49
+ - config/config.rb
50
+ - test/support/**/*.rb
51
+
52
+ Metrics/BlockLength:
53
+ Exclude:
54
+ - config/config.rb
55
+ - test/support/**/*.rb
56
+
57
+ Style/EmptyMethod:
58
+ EnforcedStyle: expanded
59
+
60
+ Layout/IndentFirstArrayElement:
61
+ EnforcedStyle: consistent
62
+
63
+ Style/AccessModifierDeclarations:
64
+ EnforcedStyle: inline
65
+
66
+ Naming/UncommunicativeMethodParamName:
67
+ Enabled: false
68
+
69
+ Lint/Debugger:
70
+ Exclude:
71
+ - test/**/*
72
+
73
+ Style/TrailingUnderscoreVariable:
74
+ Enabled: false
75
+
76
+ Naming/RescuedExceptionsVariableName:
77
+ PreferredName: error
78
+
79
+ Metrics/AbcSize:
80
+ Enabled: false
81
+
82
+ Metrics/MethodLength:
83
+ Enabled: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Encoding.default_external = "UTF-8"
2
4
  Encoding.default_internal = "UTF-8"
3
5
 
@@ -14,7 +16,8 @@ require "rack"
14
16
  require "uglifier"
15
17
  require "html_press"
16
18
 
17
- level, $VERBOSE = $VERBOSE, nil
19
+ level = $VERBOSE
20
+ $VERBOSE = nil
18
21
  require "rouge"
19
22
  require "rouge/plugins/redcarpet"
20
23
  $VERBOSE = level
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Cli < Thor
3
5
  check_unknown_options!
@@ -25,15 +27,11 @@ module Troy
25
27
  site.export_files
26
28
  end
27
29
 
28
- if options[:file]
29
- options[:file].each do |file|
30
- site.export_pages(file)
31
- end
30
+ options[:file]&.each do |file|
31
+ site.export_pages(file)
32
32
  end
33
33
 
34
- if !options[:assets] && !options[:file]
35
- site.export
36
- end
34
+ site.export if !options[:assets] && !options[:file]
37
35
  end
38
36
 
39
37
  if options[:benchmark]
@@ -53,14 +51,14 @@ module Troy
53
51
  end
54
52
 
55
53
  desc "version", "Display Troy version"
56
- map %w(-v --version) => :version
54
+ map %w[-v --version] => :version
57
55
  def version
58
56
  say "Troy #{Troy::VERSION}"
59
57
  end
60
58
 
61
59
  desc "server", "Start a server"
62
- option :port, :type => :numeric, :default => 9292, :aliases => "-p"
63
- option :host, :type => :string, :default => "0.0.0.0", :aliases => "-b"
60
+ option :port, type: :numeric, default: 9292, aliases: "-p"
61
+ option :host, type: :string, default: "0.0.0.0", aliases: "-b"
64
62
  def server
65
63
  begin
66
64
  handler = Rack::Handler::Thin
@@ -69,12 +67,13 @@ module Troy
69
67
  handler = Rack::Handler::WEBrick
70
68
  end
71
69
 
72
- handler.run Troy::Server.new(File.join(Dir.pwd, "public")), :Port => options[:port], :Host => options[:host]
70
+ handler.run Troy::Server.new(File.join(Dir.pwd, "public")), Port: options[:port], Host: options[:host]
73
71
  end
74
72
 
75
- private
76
- def site
77
- @site ||= Troy::Site.new(Dir.pwd, options)
73
+ no_commands do
74
+ def site
75
+ @site ||= Troy::Site.new(Dir.pwd, options)
76
+ end
78
77
  end
79
78
  end
80
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  ::I18n.enforce_available_locales = false
3
5
 
@@ -5,18 +7,18 @@ module Troy
5
7
  @configuration ||= Configuration.new
6
8
  end
7
9
 
8
- def self.configure(&block)
10
+ def self.configure
9
11
  yield configuration
10
12
  end
11
13
 
12
14
  class Configuration < OpenStruct
13
15
  def assets
14
- @assets ||= Configuration.new({
16
+ @assets ||= Configuration.new(
15
17
  compress_html: true,
16
18
  compress_css: true,
17
19
  compress_js: true,
18
20
  precompile: []
19
- })
21
+ )
20
22
  end
21
23
 
22
24
  def i18n
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Context
3
5
  def initialize(options = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class EmbeddedRuby
3
5
  # The template content.
@@ -1,15 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class ExtensionMatcher
3
- #
4
- #
5
5
  attr_reader :path
6
6
 
7
- #
8
- #
9
7
  attr_reader :performed
10
8
 
11
- #
12
- #
13
9
  attr_reader :matchers
14
10
 
15
11
  def initialize(path)
@@ -32,7 +28,7 @@ module Troy
32
28
  return handler.call if File.extname(path) == ext
33
29
  end
34
30
 
35
- matchers["default"].call if matchers["default"]
31
+ matchers["default"]&.call
36
32
  end
37
33
  end
38
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  # The Troy::Generator class will create a new book structure.
3
5
  #
@@ -11,7 +13,7 @@ module Troy
11
13
  desc "Generate a new site structure"
12
14
 
13
15
  def self.source_root
14
- File.expand_path("../../../templates", __FILE__)
16
+ File.expand_path("../../templates", __dir__)
15
17
  end
16
18
 
17
19
  def create_directories
@@ -1,14 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "digest/sha1"
2
4
 
3
5
  module HtmlPress
4
- CONTENT_CACHE = {}
6
+ def self.content_cache
7
+ @content_cache ||= {}
8
+ end
5
9
 
6
- def self.js_compressor (text, options = nil)
10
+ def self.js_compressor(text, options = nil)
7
11
  options ||= {}
8
12
  options[:output] ||= {inline_script: true}
9
13
 
10
14
  hash = Digest::SHA1.hexdigest(text)
11
- CONTENT_CACHE[hash] ||= MultiJs.compile(text, options).gsub(/;$/,'')
12
- CONTENT_CACHE[hash]
15
+ content_cache[hash] ||= MultiJs.compile(text, options).gsub(/;$/, "")
16
+ content_cache[hash]
13
17
  end
14
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  module Helpers
3
5
  def h(content)
@@ -20,7 +22,7 @@ module Troy
20
22
  path = site.root.join("partials/#{partial}")
21
23
  locals = locals.merge(site: site, page: page)
22
24
  EmbeddedRuby.new(path.read, locals).render
23
- rescue Exception, StandardError => error
25
+ rescue Exception => error
24
26
  raise "Unable to render #{path}; #{error.message}"
25
27
  end
26
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Markdown
3
5
  # Create a new Redcarpet renderer, that prepares the code block
@@ -31,12 +33,11 @@ module Troy
31
33
  end
32
34
 
33
35
  def renderer
34
- @renderer ||= Redcarpet::Markdown.new(Renderer, {
35
- autolink: true,
36
- space_after_headers: true,
37
- fenced_code_blocks: true,
38
- footnotes: true
39
- })
36
+ @renderer ||= Redcarpet::Markdown.new(Renderer,
37
+ autolink: true,
38
+ space_after_headers: true,
39
+ fenced_code_blocks: true,
40
+ footnotes: true)
40
41
  end
41
42
 
42
43
  def to_html
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Meta
3
5
  extend Forwardable
4
6
  def_delegators :data, :[], :fetch, :key?
5
7
 
6
- REGEX = /^---\n(.*?)\n---\n+/m
8
+ REGEX = /^---\n(.*?)\n---\n+/m.freeze
7
9
 
8
10
  attr_reader :file
9
11
 
@@ -16,14 +18,15 @@ module Troy
16
18
  end
17
19
 
18
20
  def data
19
- @data ||= (raw =~ REGEX ? YAML.load(raw[REGEX, 1]) : {})
21
+ @data ||=
22
+ raw =~ REGEX ? YAML.safe_load(raw[REGEX, 1], [Date, Time]) : {}
20
23
  end
21
24
 
22
- def method_missing(name, *args, &block)
25
+ def method_missing(name, *_args)
23
26
  data[name.to_s]
24
27
  end
25
28
 
26
- def respond_to_missing?(method, include_private = false)
29
+ def respond_to_missing?(_method, _include_private = false)
27
30
  true
28
31
  end
29
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Page
3
5
  extend Forwardable
@@ -27,33 +29,26 @@ module Troy
27
29
  @meta = meta || Meta.new(path)
28
30
  end
29
31
 
30
- #
31
- #
32
32
  def method_missing(name, *args, &block)
33
33
  return meta[name.to_s] if meta.key?(name.to_s)
34
+
34
35
  super
35
36
  end
36
37
 
37
- #
38
- #
39
- def respond_to_missing?(name, include_private = false)
38
+ def respond_to_missing?(name, _include_private = false)
40
39
  meta.key?(name.to_s)
41
40
  end
42
41
 
43
- #
44
- #
45
42
  def content
46
43
  ExtensionMatcher.new(path)
47
- .default { meta.content }
48
- .on("builder") { XML.new(meta.content, to_context).to_xml }
49
- .on("erb") { EmbeddedRuby.new(meta.content, to_context).render }
50
- .on("md") { Markdown.new(meta.content).to_html }
51
- .on("txt") { EmbeddedRuby.new(meta.content, to_context).render }
52
- .match
44
+ .default { meta.content }
45
+ .on("builder") { XML.new(meta.content, to_context).to_xml }
46
+ .on("erb") { EmbeddedRuby.new(meta.content, to_context).render }
47
+ .on("md") { Markdown.new(meta.content).to_html }
48
+ .on("txt") { EmbeddedRuby.new(meta.content, to_context).render }
49
+ .match
53
50
  end
54
51
 
55
- #
56
- #
57
52
  def to_context
58
53
  {
59
54
  page: self,
@@ -61,8 +56,6 @@ module Troy
61
56
  }
62
57
  end
63
58
 
64
- #
65
- #
66
59
  def compress(content)
67
60
  content = HtmlPress.press(content) if config.assets.compress_html
68
61
  content
@@ -72,38 +65,30 @@ module Troy
72
65
  #
73
66
  def render
74
67
  ExtensionMatcher.new(path)
75
- .default { content }
76
- .on("html") { compress render_erb }
77
- .on("md") { compress render_erb }
78
- .on("erb") { compress render_erb }
79
- .match
68
+ .default { content }
69
+ .on("html") { compress render_erb }
70
+ .on("md") { compress render_erb }
71
+ .on("erb") { compress render_erb }
72
+ .match
80
73
  end
81
74
 
82
- #
83
- #
84
75
  def permalink
85
76
  meta.fetch("permalink", File.basename(path).gsub(/\..*?$/, ""))
86
77
  end
87
78
 
88
- #
89
- #
90
79
  def filename
91
80
  ExtensionMatcher.new(path)
92
- .default { "#{permalink}.html" }
93
- .on("builder") { "#{permalink}.xml" }
94
- .on("xml") { "#{permalink}.xml" }
95
- .on("txt") { "#{permalink}.txt" }
96
- .match
81
+ .default { "#{permalink}.html" }
82
+ .on("builder") { "#{permalink}.xml" }
83
+ .on("xml") { "#{permalink}.xml" }
84
+ .on("txt") { "#{permalink}.txt" }
85
+ .match
97
86
  end
98
87
 
99
- #
100
- #
101
88
  def layout
102
- site.root.join("layouts/#{meta.fetch("layout", "default")}.erb")
89
+ site.root.join("layouts/#{meta.fetch('layout', 'default')}.erb")
103
90
  end
104
91
 
105
- #
106
- #
107
92
  def render_erb
108
93
  if layout.exist?
109
94
  EmbeddedRuby.new(
@@ -125,25 +110,19 @@ module Troy
125
110
  end
126
111
  end
127
112
 
128
- #
129
- #
130
113
  def output_file
131
114
  base = File.dirname(path)
132
- .gsub(site.root.join("source").to_s, "")
133
- .gsub(%r[^/], "")
115
+ .gsub(site.root.join("source").to_s, "")
116
+ .gsub(%r{^/}, "")
134
117
 
135
118
  site.root.join("public", base, filename)
136
119
  end
137
120
 
138
- #
139
- #
140
121
  def save
141
122
  FileUtils.mkdir_p(File.dirname(output_file))
142
123
  save_to(output_file)
143
124
  end
144
125
 
145
- #
146
- #
147
126
  def config
148
127
  Troy.configuration
149
128
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Server
3
5
  attr_reader :root, :request
@@ -13,7 +15,9 @@ module Troy
13
15
 
14
16
  def render(status, content_type, path)
15
17
  last_modified = path.mtime.httpdate
16
- return [304, {}, []] if request.env["HTTP_IF_MODIFIED_SINCE"] == last_modified
18
+ if request.env["HTTP_IF_MODIFIED_SINCE"] == last_modified
19
+ return [304, {}, []]
20
+ end
17
21
 
18
22
  headers = {
19
23
  "Content-Type" => content_type,
@@ -26,7 +30,7 @@ module Troy
26
30
  end
27
31
 
28
32
  def normalized_path
29
- path = request.path.gsub(%r[/$], "")
33
+ path = request.path.gsub(%r{/$}, "")
30
34
  path << "?#{request.query_string}" unless request.query_string.empty?
31
35
  path
32
36
  end
@@ -36,7 +40,7 @@ module Troy
36
40
  end
37
41
 
38
42
  def process
39
- path = request.path[%r[^/(.*?)/?$], 1]
43
+ path = request.path[%r{^/(.*?)/?$}, 1]
40
44
  path = "index" if path == ""
41
45
  path = root.join(path)
42
46
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class Site
3
5
  attr_accessor :root, :options
@@ -11,30 +13,22 @@ module Troy
11
13
  set_locale
12
14
  end
13
15
 
14
- #
15
- #
16
16
  def load_extensions
17
17
  Dir[root.join("config/**/*helpers.rb")].each do |file|
18
18
  require file
19
19
  end
20
20
  end
21
21
 
22
- #
23
- #
24
22
  def set_locale
25
23
  I18n.load_path += config.i18n.load_path
26
24
  I18n.default_locale = config.i18n.locale
27
25
  I18n.locale = config.i18n.locale
28
26
  end
29
27
 
30
- #
31
- #
32
28
  def load_configuration
33
29
  load root.join("config/troy.rb")
34
30
  end
35
31
 
36
- #
37
- #
38
32
  def export
39
33
  remove_public_dir
40
34
  export_assets
@@ -42,8 +36,6 @@ module Troy
42
36
  export_pages
43
37
  end
44
38
 
45
- #
46
- #
47
39
  def export_files
48
40
  assets = root.join("assets")
49
41
 
@@ -57,18 +49,15 @@ module Troy
57
49
  def export_file(assets, entry)
58
50
  basename = entry.to_s
59
51
  return if [".", "..", "javascripts", "stylesheets"].include?(basename)
52
+
60
53
  FileUtils.rm_rf root.join("public/#{basename}")
61
54
  FileUtils.cp_r assets.join(entry), root.join("public/#{basename}")
62
55
  end
63
56
 
64
- #
65
- #
66
57
  def remove_public_dir
67
58
  FileUtils.rm_rf root.join("public")
68
59
  end
69
60
 
70
- #
71
- #
72
61
  def export_pages(file = nil)
73
62
  file = File.expand_path(file) if file
74
63
 
@@ -76,21 +65,27 @@ module Troy
76
65
  .select {|page| file.nil? || page.path == file }
77
66
  .each_slice(options[:concurrency]) do |slice|
78
67
  threads = slice.map do |page|
79
- Thread.new { page.save }
68
+ Thread.new do
69
+ page.save
70
+ end
80
71
  end
81
72
 
82
73
  threads.each(&:join)
83
74
  end
84
75
  end
85
76
 
86
- #
87
- #
88
77
  def export_assets
89
78
  sprockets = Sprockets::Environment.new
90
79
  sprockets.append_path root.join("assets/javascripts")
91
80
  sprockets.append_path root.join("assets/stylesheets")
92
- sprockets.css_compressor = Sprockets::SassCompressor if config.assets.compress_css
93
- sprockets.js_compressor = Uglifier.new(uglifier_options) if config.assets.compress_js
81
+
82
+ if config.assets.compress_css
83
+ sprockets.css_compressor = Sprockets::SassCompressor
84
+ end
85
+
86
+ if config.assets.compress_js
87
+ sprockets.js_compressor = Uglifier.new(uglifier_options)
88
+ end
94
89
 
95
90
  config.assets.precompile.each_slice(options[:concurrency]) do |slice|
96
91
  slice.map do |asset_name|
@@ -101,26 +96,21 @@ module Troy
101
96
 
102
97
  def export_asset(sprockets, asset_name)
103
98
  asset = sprockets[asset_name]
104
- output_file = asset.pathname.to_s
105
- .gsub(root.join("assets").to_s, "")
106
- .gsub(%r[^/], "")
107
- .gsub(/\.scss$/, ".css")
108
- .gsub(/\.coffee$/, ".js")
99
+ output_file = asset.filename.to_s
100
+ .gsub(root.join("assets").to_s, "")
101
+ .gsub(%r{^/}, "")
102
+ .gsub(/\.scss$/, ".css")
103
+ .gsub(/\.coffee$/, ".js")
109
104
 
110
105
  asset.write_to root.join("public/#{output_file}")
111
106
  end
112
107
 
113
- #
114
- #
115
- #
116
108
  def uglifier_options
117
109
  options = Uglifier::DEFAULTS.dup
118
110
  options[:output][:comments] = :none
119
111
  options
120
112
  end
121
113
 
122
- #
123
- #
124
114
  def source
125
115
  Dir[root.join("source/**/*.{html,erb,md,builder,xml,txt}").to_s]
126
116
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
- VERSION = "0.0.35"
4
+ VERSION = "0.0.36"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Troy
2
4
  class XML
3
5
  # The XML content.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: troy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-26 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -215,6 +215,7 @@ extensions: []
215
215
  extra_rdoc_files: []
216
216
  files:
217
217
  - ".gitignore"
218
+ - ".rubocop.yml"
218
219
  - Gemfile
219
220
  - LICENSE.txt
220
221
  - README.md
@@ -268,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  - !ruby/object:Gem::Version
269
270
  version: '0'
270
271
  requirements: []
271
- rubyforge_project:
272
- rubygems_version: 2.7.6
272
+ rubygems_version: 3.0.3
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: A static site generator