Justicar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 408dfbb73b156132cf179a3f64fa235ef7b9075f5f3742e1245b6ebdb2a1e12f
4
+ data.tar.gz: c39d1918d45a312c9ad4c05edcc4dcca5ef2de37e286d7a3621f38925289ec28
5
+ SHA512:
6
+ metadata.gz: 3398a9b7c42ad27cf586671e3c24d93c1affcdceb21d4905129e80755b9e79fb7790ae846bab0434d9e5de2493c1f2db474604c47975c2de7c8d8762eff45d69
7
+ data.tar.gz: ccf19ce74161fcedad9b5a7f505c1e2bc6eea525d3205e4df7c754cf60fda081026e70031691565bedc958310865c0da47982fcba2eb01e6fef6acdbcbc49fe0
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-04-20
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Justicar.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Justicar.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/Justicar/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "Justicar"
7
+ spec.version = Justicar::VERSION
8
+ spec.authors = ["_Tradam"]
9
+ spec.email = ["github@tradam.dev"]
10
+
11
+ spec.summary = "A Ruby obsessed static website generator that does web development Justice!"
12
+ #spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://github.com/realtradam/Justicar"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+ spec.add_dependency 'paggio', '~> 0.3.0'
37
+ spec.add_dependency 'opal', '~> 1.5'
38
+ spec.add_dependency 'opal-browser', '~> 0.3.3'
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 _Tradam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.mdown ADDED
@@ -0,0 +1,49 @@
1
+ # Justicar
2
+
3
+ A Ruby obsessed static website generator that does web development Justice!
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ $ gem install Justicar
10
+
11
+ ## Usage
12
+
13
+ Using the CLI:
14
+
15
+ ```sh
16
+ $ justicar my_project # <- this generates a new project
17
+ $ cd my_project
18
+ $ bundle install # <- installs dependencies
19
+ $ rake build # <- generates the website
20
+ $ rake serve # <- locally host the project
21
+ ```
22
+
23
+ ### How it works:
24
+
25
+ #### Source Dir:
26
+
27
+ HTML and CSS gets compiled using Paggio while Js gets compiled using Opal.
28
+
29
+ #### Public Dir:
30
+
31
+ This is where static non-generated files go such as Images.
32
+
33
+ #### Build Dir:
34
+
35
+ Build is where your generated site gets exported to.
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/realtradam/Justicar.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/exe/justicar ADDED
@@ -0,0 +1,26 @@
1
+ #!/bin/ruby
2
+
3
+ require 'fileutils'
4
+
5
+ template_path = File.expand_path(File.dirname(__FILE__) + '/../template')
6
+
7
+ def help
8
+ puts 'Pass a path as an argument to generate a new project'
9
+ end
10
+
11
+ if ARGV.length == 0 || ARGV.first.chars.first == '-'
12
+ help
13
+ elsif ARGV.length == 1
14
+ begin
15
+ if ARGV.first.chars.first == '/'
16
+ FileUtils.copy_entry(template_path, ARGV.first)
17
+ else
18
+ FileUtils.copy_entry(template_path, "#{Dir.pwd}/#{ARGV.first}")
19
+ end
20
+ puts "Project generated"
21
+ rescue
22
+ help
23
+ end
24
+ else
25
+ help
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Justicar
4
+ VERSION = "0.1.0"
5
+ end
data/lib/Justicar.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "Justicar/version"
4
+ require "paggio"
5
+ require "opal"
6
+
7
+ class Justicar
8
+ class << self
9
+
10
+ def load_templates(dir)
11
+ Dir.each_child(dir) do |file|
12
+ if File.directory? "#{dir}/#{file}"
13
+ self.load_templates "#{dir}/#{file}"
14
+ else
15
+ load "#{dir}/#{file}"
16
+ end
17
+ end
18
+ end
19
+
20
+ def build_source(dir, target = self.output)
21
+
22
+ # only add root path
23
+ unless self.opl_path
24
+ opl_path = true
25
+ opl.append_paths dir
26
+ end
27
+
28
+ Dir.each_child(dir) do |full_file_name|
29
+ file_name, extension, _rb = full_file_name.split('.')
30
+ if File.directory?("#{dir}/#{full_file_name}")
31
+ target[full_file_name] = {}
32
+ self.build_source("#{dir}/#{full_file_name}", target[full_file_name])
33
+ else
34
+ if ['html', 'css'].include? extension
35
+ File.open("#{dir}/#{full_file_name}", 'r') do |file|
36
+ target[full_file_name] = instance_eval(file.read)
37
+ end
38
+ elsif extension == 'js'
39
+ opl_file, _dot, _extension = full_file_name.partition('.')
40
+ opl_file = "#{"#{dir}/".partition('/').last}#{opl_file}"
41
+ target[full_file_name] = opl.build(opl_file).to_s
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def build(target_dir, public_dir, hash = self.output)
48
+ if Dir.exist? target_dir
49
+ FileUtils.rm_r target_dir
50
+ end
51
+ if Dir.exist? public_dir
52
+ FileUtils.copy_entry(public_dir, target_dir)
53
+ else
54
+ FileUtils.mkdir target_dir
55
+ end
56
+ hash.each do |key, val|
57
+ puts "key: #{key}, val: #{val}"
58
+ if val.is_a? String
59
+ file_name, type, _rb = key.to_s.split('.')
60
+ puts "filename: #{file_name}, type: #{type}"
61
+ File.open("#{target_dir}/#{file_name}.#{type}", "w") do |file|
62
+ file.write(val)
63
+ end
64
+ else
65
+ unless Dir.exist? "#{target_dir}/#{key}"
66
+ FileUtils.mkdir "#{target_dir}/#{key}"
67
+ end
68
+ self.build("#{target_dir}/#{key}", hash)
69
+ end
70
+ end
71
+ puts File.expand_path(File.dirname(__FILE__))
72
+ end
73
+
74
+ def output
75
+ @output ||= {}
76
+ end
77
+
78
+ def opl
79
+ @opl ||= Opal::Builder.new
80
+ end
81
+
82
+ attr_accessor :opl_path
83
+
84
+ end
85
+
86
+ end
data/sig/Justicar.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Justicar
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/template/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'Justicar'
2
+ require 'opal-browser'
3
+
4
+ desc "Build your website"
5
+ task :build do
6
+ Justicar.build_source('src')
7
+ Justicar.build('build', 'public')
8
+ end
9
+
10
+ desc "Create a server and open your site in your browser"
11
+ task :serve do
12
+ link = "http://localhost:8000/index.html"
13
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
14
+ system "start #{link}"
15
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin/
16
+ system "open #{link}"
17
+ elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
18
+ system "xdg-open #{link}"
19
+ end
20
+ `ruby -run -ehttpd build -p8000`
21
+ end
@@ -0,0 +1,12 @@
1
+ Paggio.html do
2
+ script type: "text/javascript", src: "script.js"
3
+ link rel: "stylesheet", href: "style.css"
4
+ h1 { "Hello world from Justicar" }
5
+ hr
6
+ h2.paggio do
7
+ 'Hello world from Paggio!'
8
+ end
9
+ p.paggio do
10
+ "This part was generated by Paggio in HTML :)"
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'opal'
2
+ require 'native'
3
+ require 'promise'
4
+ require 'browser/setup/full'
5
+
6
+ $document.ready do
7
+ DOM do
8
+ h2.opal do
9
+ "Hello World from Opal!"
10
+ end
11
+ p.opal {"This part was generated by Opal from Javascript (:"}
12
+ end.append_to($document.body)
13
+ end
@@ -0,0 +1,13 @@
1
+ Paggio.css do
2
+ rule '.opal' do
3
+ color :dodgerblue
4
+ end
5
+
6
+ rule '.paggio' do
7
+ color :goldenrod
8
+ end
9
+
10
+ rule 'h1' do
11
+ font style: :italic
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Justicar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - _Tradam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paggio
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: opal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: opal-browser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.3
55
+ description:
56
+ email:
57
+ - github@tradam.dev
58
+ executables:
59
+ - justicar
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - Justicar.gemspec
67
+ - LICENSE.txt
68
+ - README.mdown
69
+ - Rakefile
70
+ - exe/justicar
71
+ - lib/Justicar.rb
72
+ - lib/Justicar/version.rb
73
+ - sig/Justicar.rbs
74
+ - template/Rakefile
75
+ - template/src/index.html.rb
76
+ - template/src/script.js.rb
77
+ - template/src/style.css.rb
78
+ homepage: https://github.com/realtradam/Justicar
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ homepage_uri: https://github.com/realtradam/Justicar
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.6.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.3.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A Ruby obsessed static website generator that does web development Justice!
102
+ test_files: []