newport 1.0.2 → 1.0.4

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
  SHA256:
3
- metadata.gz: bb6ab1eeff24f4cd07bce215f8d14e19e4c92207eb2f97ea7f33dd5ba1c9dabb
4
- data.tar.gz: e9a58fb2020254c107d074664262a2eb5d94dc46a94bc3c27b3753e960b87857
3
+ metadata.gz: cde9ad6247ebf9abbfd0e1b6039567784b7a69f995bbe36f435a3cd15a4a6f30
4
+ data.tar.gz: 5af60fc2e02d5fd95c0b679f4b356b0c776ebf592e25e85fd7068989b73f523a
5
5
  SHA512:
6
- metadata.gz: 0c46b1a629c225301a29f8436d2b64be4de59e142af8dfd8a08fd3455459c2d9d3d3d4f5a1335861e8cba744398a1245f794ab4696b7b55fc263613bd9000083
7
- data.tar.gz: 1653d06aee24da17a31612717877be50c3173378359849e1fd5fb76e822f16f4bf68f638d325b16a7afb897eeef5bbce5e31efc5e455603a5ebe1697ac229f1d
6
+ metadata.gz: 16e7c45707884e45a018a6144852880e39e8882fc3acc9cb9e0342a8a7d19c8bdd6f1c6096e34259e8a91bb4762bab97b74afff302909451740a1c6761517bb5
7
+ data.tar.gz: 711c06ca630378be05a3776eddf85c0723b2992cea619cb429a367a97ed710e9b66dbdc5566f2c92371d3b31e8a029029fe8db8483e831bae72c8e7ca1e8b4f9
data/exe/newport CHANGED
@@ -5,7 +5,7 @@ $stdout.sync = true
5
5
 
6
6
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
7
7
 
8
- require '../lib/newport'
8
+ require 'newport'
9
9
 
10
10
  Newport::Help.show && abort if ARGV.length.zero? || ARGV[0] == 'help'
11
11
 
data/lib/newport.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift __dir__ # For use/testing when no gem is installed
4
+
5
+ def require_all(path)
6
+ glob = File.join(__dir__, path, '*.rb')
7
+ Dir[glob].each do |f|
8
+ require f
9
+ end
10
+ end
11
+
12
+ require 'rubygems'
13
+ require 'fileutils'
14
+ require 'time'
15
+ require 'logger'
16
+ require 'colorator'
17
+ require 'kramdown'
18
+ require 'rss'
19
+
20
+ module Newport
21
+ autoload :VERSION, 'newport/version'
22
+ autoload :Help, 'newport/help'
23
+ autoload :New, 'newport/new'
24
+ autoload :Build, 'newport/build'
25
+
26
+ require 'newport/logger'
27
+
28
+ class << self
29
+ def logger
30
+ @logger ||= Logger.new($stdout)
31
+ @logger.formatter = proc { |_severity, _datetime, _progname, msg| "#{msg}\n" }
32
+ @logger
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Newport
4
+ class Build
5
+ class << self
6
+ def process(args)
7
+ show_help if args[1] == 'help'
8
+ build_blog
9
+ end
10
+
11
+ private
12
+
13
+ def show_help
14
+ Newport.logger.info "Newport #{Newport::VERSION}"
15
+ Newport.logger.info 'usage: newport build'
16
+ abort
17
+ end
18
+
19
+ def build_blog
20
+ html = content_from_layouts
21
+ html = add_javascript html
22
+ html = add_plugins html
23
+ html = add_posts(html, build_posts)
24
+ html = replcae_tags html
25
+ write_html html
26
+ end
27
+
28
+ def config
29
+ @config ||= YAML.load_file('config.yml')
30
+ end
31
+
32
+ def content_from_layouts
33
+ head = File.read('layouts/head.html')
34
+ style = File.read('layouts/style.css')
35
+ head = head.gsub('<!-- style -->', "<style>#{style}</style>")
36
+ nav = File.read('layouts/nav.html')
37
+ main = File.read('layouts/main.html')
38
+ footer = File.read('layouts/footer.html')
39
+ main.gsub('<!-- head -->', head).gsub('<!-- nav -->', nav).gsub('<!-- footer -->', footer)
40
+ end
41
+
42
+ def add_javascript(html)
43
+ jss = []
44
+ Dir.glob('javascript/*.js') { |filename| jss << File.open(filename).read }
45
+ html.gsub('<!-- javascript -->', "<script>#{jss.join}</script>")
46
+ end
47
+
48
+ def add_plugins(html)
49
+ plugins = []
50
+ config['plugins'].each do |p|
51
+ plugin = File.open("plugins/#{p}.js").read
52
+ plugins << plugin
53
+ end
54
+ html.gsub('<!-- plugins -->', "<script>#{plugins.join}</script>")
55
+ end
56
+
57
+ def build_posts
58
+ files = []
59
+ posts = []
60
+
61
+ Dir.glob('posts/*.md') { |filename| files << filename.split('/').last }
62
+
63
+ files.reverse.each do |filename|
64
+ post = '<article>' + Kramdown::Document.new(File.open("posts/#{filename}").read).to_html + '</article>'
65
+ posts << post
66
+ end
67
+ posts
68
+ end
69
+
70
+ def add_posts(html, posts)
71
+ html.gsub('<!-- posts -->', posts.join)
72
+ end
73
+
74
+ def replcae_tags(html)
75
+ html = html.gsub('<!-- email -->', config['email'])
76
+ html.gsub('<!-- title -->', config['title'])
77
+ end
78
+
79
+ def write_html(html)
80
+ FileUtils.mkdir_p 'production/images'
81
+ File.open('production/index.html', 'w') do |f|
82
+ f.write html
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Newport
4
+ class Help
5
+ class << self
6
+ def show
7
+ Newport.logger.info "Newport #{Newport::VERSION}"
8
+ Newport.logger.info 'usage: newport [command] [options]'
9
+ Newport.logger.info 'commands: new, build, help'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Logger
4
+ def abort_with(msg)
5
+ error(msg)
6
+ abort
7
+ end
8
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Newport
4
+ class New
5
+ class << self
6
+ def process(args)
7
+ Newport.logger.abort_with 'fatal: please specify path.'.red unless args[1]
8
+ show_help if args[1] == 'help'
9
+ create_blog args[1]
10
+ end
11
+
12
+ private
13
+
14
+ def show_help
15
+ Newport.logger.info "Newport #{Newport::VERSION}"
16
+ Newport.logger.info 'usage: newport new [path]'
17
+ abort
18
+ end
19
+
20
+ def create_blog(path)
21
+ blog_path = File.expand_path(path, Dir.pwd)
22
+ FileUtils.mkdir_p blog_path
23
+ FileUtils.cp_r "#{template}/.", path
24
+ FileUtils.chmod_R 'u+w', path
25
+ File.open(File.expand_path('Gemfile', path), 'w') do |f|
26
+ f.write(gemfile_contents)
27
+ end
28
+ after_install path
29
+ end
30
+
31
+ def template
32
+ File.expand_path('../site_template', __dir__)
33
+ end
34
+
35
+ def gemfile_contents
36
+ <<~RUBY
37
+ source "https://rubygems.org"
38
+
39
+ gem "newport", "~> #{Newport::VERSION}"
40
+
41
+ # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
42
+ # and associated library.
43
+ platforms :mingw, :x64_mingw, :mswin, :jruby do
44
+ gem "tzinfo", "~> 1.2"
45
+ gem "tzinfo-data"
46
+ end
47
+ RUBY
48
+ end
49
+
50
+ def after_install(path)
51
+ begin
52
+ require 'bundler'
53
+ bundle_install path
54
+ rescue LoadError
55
+ Newport.logger.info 'Could not load Bundler. Bundle install skipped.'
56
+ end
57
+
58
+ Newport.logger.info "New Newport site installed in #{path.cyan}."
59
+ end
60
+
61
+ def bundle_install(path)
62
+ Newport.logger.info "Running bundle install in #{path.cyan}..."
63
+ Dir.chdir(path) do
64
+ system('bundle')
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Newport
4
+ VERSION = '1.0.4'
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Fisher
@@ -97,6 +97,12 @@ files:
97
97
  - LICENSE
98
98
  - README.md
99
99
  - exe/newport
100
+ - lib/newport.rb
101
+ - lib/newport/build.rb
102
+ - lib/newport/help.rb
103
+ - lib/newport/logger.rb
104
+ - lib/newport/new.rb
105
+ - lib/newport/version.rb
100
106
  homepage: https://github.com/richard-fisher/newport
101
107
  licenses:
102
108
  - MIT