argon18 0.1.1 → 0.2.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/argon18 +10 -3
  3. data/lib/argon18.rb +44 -0
  4. data/lib/server/app.rb +1 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e47b5041df33ef7aa244272c3f646c18dc4aa29894810ec79c841f727b701ea8
4
- data.tar.gz: d8336d5a0b72a322435c57ba6bca22f178d8d8a900f822406a684efcd1d80e80
3
+ metadata.gz: 7860f1a5f96ac95590a1eab34aa06abbbdf76f9c4b7527915c980e20e99361b4
4
+ data.tar.gz: 5c31eed89e738b7cd2e5346d42ebb3745724b8965933d8f60391d13ef104525d
5
5
  SHA512:
6
- metadata.gz: 5c4a4fca6e0f82c4b43cbc7b1bd6c0256045974aa72eec3d162325b0982935994a7adf2733e46a79bfbc23c2fc85db8c2a0ff2f9b3c1ed1ad41adeaa22779cc3
7
- data.tar.gz: a251e89f5ea2053bcc64a0c8a60c19d0bee71c23e74ef3691f5f2dc3b5283057847faaa743572169c39d9ea500c00a2dac03f7cfeae2bac4c0b54470d51ebc39
6
+ metadata.gz: ea28a8f0971575d7d8c81ed80ecb402c17e429db727e16c02ad3386b982e372f8349cdd74ddf03688d46fe8e19c44656c1a20ccfbc80c697f6ed3dfbda169132
7
+ data.tar.gz: 4ced5e57fa3bb13194d061853ea94c97478f98a7043cf759d99e21f8909fe6c0459dfb6986228a4fbae7a81f34a8c894876b3ad0a7c5c0cbe5b14003c2710d15
@@ -6,6 +6,8 @@ ARGV = []
6
6
 
7
7
  require 'argon18'
8
8
 
9
+ flags = ["-h", "--help", "-E"]
10
+
9
11
  if args.include? "-h" or args.include? "--help"
10
12
  puts(
11
13
  "
@@ -15,13 +17,18 @@ Start a web server in a given directory.
15
17
  With no DIRECTORY the current working directory is used.
16
18
 
17
19
  -h, --help display this message and exit
20
+ -E export the site to static html files (will be placed in project_root/output)
18
21
  "
19
22
  )
20
23
  else
21
24
  project_root = "."
22
- if args[0]
23
- project_root = args[0]
25
+ if args[-1] && !(flags.include? args[-1])
26
+ project_root = args[-1]
27
+ end
28
+ if args.include? "-E" or args.include? "--export"
29
+ Argon.gen_static_html project_root
30
+ else
31
+ Argon.run_app project_root
24
32
  end
25
- Argon.run_app project_root
26
33
  end
27
34
 
@@ -1,9 +1,14 @@
1
1
  require 'sinatra'
2
2
  require 'slim'
3
3
  require 'rack'
4
+ require 'fileutils'
4
5
 
5
6
  require 'server/app.rb'
6
7
 
8
+ class SlimEnv
9
+ attr_accessor :name
10
+ end
11
+
7
12
  class Argon
8
13
  def self.run_app(project_root)
9
14
  ENV['project_root'] = File.expand_path(project_root)
@@ -14,4 +19,43 @@ class Argon
14
19
  Rack::Handler::WEBrick.run(ArgonApp, Port: 9292)
15
20
  end
16
21
  end
22
+
23
+ def self.gen_static_html(project_root)
24
+ ENV['project_root'] = File.expand_path(project_root)
25
+ ENV['views_path'] = "views"
26
+ ENV['public_path'] = "public"
27
+ ENV['output_path'] = ENV['project_root'] + "/" + "output/"
28
+
29
+ FileUtils.mkdir_p ENV['output_path']
30
+
31
+ Dir.chdir(ENV['project_root']) do
32
+ files = []
33
+ dir_stack = [ENV['views_path']]
34
+ p dir_stack
35
+
36
+ slim_env = SlimEnv.new
37
+ slim_env.name = "Argon18"
38
+ # Copy media
39
+ FileUtils.cp_r "#{ENV['public_path']}/.", ENV['output_path']
40
+
41
+ # Render slim files
42
+ while !dir_stack.empty?
43
+ curr_dir = (dir_stack.delete_at 0).split("views/")[-1]
44
+ FileUtils.mkdir_p (ENV['output_path'] + curr_dir)
45
+ Dir[curr_dir + "/*"].each { |d| dir_stack << d }
46
+ dir_stack.filter! { |f| File.directory? f }
47
+
48
+ files = Dir[curr_dir + "/*.slim"]
49
+ p files
50
+ files.each do |f|
51
+ content = File.read f
52
+ parsed = Slim::Template.new { content }.render(slim_env)
53
+ parsed = parsed.gsub(/href="\/"/, 'href="index.html"')
54
+ parsed = parsed.gsub(/href="([^".]+)"/, 'href="\1.html"')
55
+ base_name = f.split(".")[0].split("views/")[-1]
56
+ File.write ENV['output_path'] + base_name + ".html", parsed
57
+ end
58
+ end
59
+ end
60
+ end
17
61
  end
@@ -7,6 +7,7 @@ class ArgonApp < Sinatra::Base
7
7
  end
8
8
 
9
9
  get '/' do
10
+ puts (slim :index)
10
11
  slim :index
11
12
  end
12
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argon18
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Udén
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.0.6
82
+ rubygems_version: 3.1.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Argon 18 ⚛️