summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-04-21 07:55:45 -0400
committerrealtradam <[email protected]>2022-04-21 07:55:45 -0400
commit8c0569bf34405dfdf0968b26f33dd70976866943 (patch)
tree321cc6e1b0840b0eebf84523dcd6486cabaab3c6
downloadJusticar-0.1.0.tar.gz
Justicar-0.1.0.zip
initv0.1.0
-rw-r--r--.gitignore8
-rw-r--r--.rubocop.yml13
-rw-r--r--CHANGELOG.md5
-rw-r--r--Gemfile10
-rw-r--r--Justicar.gemspec41
-rw-r--r--LICENSE.txt21
-rw-r--r--README.mdown49
-rw-r--r--Rakefile8
-rwxr-xr-xbin/console15
-rwxr-xr-xbin/setup8
-rw-r--r--exe/justicar26
-rw-r--r--lib/Justicar.rb86
-rw-r--r--lib/Justicar/version.rb5
-rw-r--r--sig/Justicar.rbs4
-rw-r--r--template/Rakefile21
-rw-r--r--template/src/index.html.rb12
-rw-r--r--template/src/script.js.rb13
-rw-r--r--template/src/style.css.rb13
18 files changed, 358 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9106b2a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+/.bundle/
+/.yardoc
+/_yardoc/
+/coverage/
+/doc/
+/pkg/
+/spec/reports/
+/tmp/
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..e3462a7
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,13 @@
+AllCops:
+ TargetRubyVersion: 2.6
+
+Style/StringLiterals:
+ Enabled: true
+ EnforcedStyle: double_quotes
+
+Style/StringLiteralsInInterpolation:
+ Enabled: true
+ EnforcedStyle: double_quotes
+
+Layout/LineLength:
+ Max: 120
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..148f4a9
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,5 @@
+## [Unreleased]
+
+## [0.1.0] - 2022-04-20
+
+- Initial release
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..3b8a2a3
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+# Specify your gem's dependencies in Justicar.gemspec
+gemspec
+
+gem "rake", "~> 13.0"
+
+gem "rubocop", "~> 1.21"
diff --git a/Justicar.gemspec b/Justicar.gemspec
new file mode 100644
index 0000000..b33f7d0
--- /dev/null
+++ b/Justicar.gemspec
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require_relative "lib/Justicar/version"
+
+Gem::Specification.new do |spec|
+ spec.name = "Justicar"
+ spec.version = Justicar::VERSION
+ spec.authors = ["_Tradam"]
+ spec.email = ["[email protected]"]
+
+ spec.summary = "A Ruby obsessed static website generator that does web development Justice!"
+ #spec.description = "TODO: Write a longer description or delete this line."
+ spec.homepage = "https://github.com/realtradam/Justicar"
+ spec.license = "MIT"
+ spec.required_ruby_version = ">= 2.6.0"
+
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
+
+ spec.metadata["homepage_uri"] = spec.homepage
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
+
+ # Specify which files should be added to the gem when it is released.
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
+ spec.files = Dir.chdir(__dir__) do
+ `git ls-files -z`.split("\x0").reject do |f|
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
+ end
+ end
+ spec.bindir = "exe"
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
+
+ # Uncomment to register a new dependency of your gem
+ # spec.add_dependency "example-gem", "~> 1.0"
+ spec.add_dependency 'paggio', '~> 0.3.0'
+ spec.add_dependency 'opal', '~> 1.5'
+ spec.add_dependency 'opal-browser', '~> 0.3.3'
+ # For more information and examples about making a new gem, check out our
+ # guide at: https://bundler.io/guides/creating_gem.html
+end
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..3130fcb
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2022 _Tradam
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.mdown b/README.mdown
new file mode 100644
index 0000000..19cd579
--- /dev/null
+++ b/README.mdown
@@ -0,0 +1,49 @@
+# Justicar
+
+A Ruby obsessed static website generator that does web development Justice!
+
+## Installation
+
+Install the gem:
+
+ $ gem install Justicar
+
+## Usage
+
+Using the CLI:
+
+```sh
+$ justicar my_project # <- this generates a new project
+$ cd my_project
+$ bundle install # <- installs dependencies
+$ rake build # <- generates the website
+$ rake serve # <- locally host the project
+```
+
+### How it works:
+
+#### Source Dir:
+
+HTML and CSS gets compiled using Paggio while Js gets compiled using Opal.
+
+#### Public Dir:
+
+This is where static non-generated files go such as Images.
+
+#### Build Dir:
+
+Build is where your generated site gets exported to.
+
+## Development
+
+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.
+
+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).
+
+## Contributing
+
+Bug reports and pull requests are welcome on GitHub at https://github.com/realtradam/Justicar.
+
+## License
+
+The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..1924143
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+require "bundler/gem_tasks"
+require "rubocop/rake_task"
+
+RuboCop::RakeTask.new
+
+task default: :rubocop
diff --git a/bin/console b/bin/console
new file mode 100755
index 0000000..b8004c6
--- /dev/null
+++ b/bin/console
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require "bundler/setup"
+require "Justicar"
+
+# You can add fixtures and/or initialization code here to make experimenting
+# with your gem easier. You can also use a different console, if you like.
+
+# (If you use this, don't forget to add pry to your Gemfile!)
+# require "pry"
+# Pry.start
+
+require "irb"
+IRB.start(__FILE__)
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000..dce67d8
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+set -euo pipefail
+IFS=$'\n\t'
+set -vx
+
+bundle install
+
+# Do any other automated setup that you need to do here
diff --git a/exe/justicar b/exe/justicar
new file mode 100644
index 0000000..efd75af
--- /dev/null
+++ b/exe/justicar
@@ -0,0 +1,26 @@
+#!/bin/ruby
+
+require 'fileutils'
+
+template_path = File.expand_path(File.dirname(__FILE__) + '/../template')
+
+def help
+ puts 'Pass a path as an argument to generate a new project'
+end
+
+if ARGV.length == 0 || ARGV.first.chars.first == '-'
+ help
+elsif ARGV.length == 1
+ begin
+ if ARGV.first.chars.first == '/'
+ FileUtils.copy_entry(template_path, ARGV.first)
+ else
+ FileUtils.copy_entry(template_path, "#{Dir.pwd}/#{ARGV.first}")
+ end
+ puts "Project generated"
+ rescue
+ help
+ end
+else
+ help
+end
diff --git a/lib/Justicar.rb b/lib/Justicar.rb
new file mode 100644
index 0000000..e57845e
--- /dev/null
+++ b/lib/Justicar.rb
@@ -0,0 +1,86 @@
+# frozen_string_literal: true
+
+require_relative "Justicar/version"
+require "paggio"
+require "opal"
+
+class Justicar
+ class << self
+
+ def load_templates(dir)
+ Dir.each_child(dir) do |file|
+ if File.directory? "#{dir}/#{file}"
+ self.load_templates "#{dir}/#{file}"
+ else
+ load "#{dir}/#{file}"
+ end
+ end
+ end
+
+ def build_source(dir, target = self.output)
+
+ # only add root path
+ unless self.opl_path
+ opl_path = true
+ opl.append_paths dir
+ end
+
+ Dir.each_child(dir) do |full_file_name|
+ file_name, extension, _rb = full_file_name.split('.')
+ if File.directory?("#{dir}/#{full_file_name}")
+ target[full_file_name] = {}
+ self.build_source("#{dir}/#{full_file_name}", target[full_file_name])
+ else
+ if ['html', 'css'].include? extension
+ File.open("#{dir}/#{full_file_name}", 'r') do |file|
+ target[full_file_name] = instance_eval(file.read)
+ end
+ elsif extension == 'js'
+ opl_file, _dot, _extension = full_file_name.partition('.')
+ opl_file = "#{"#{dir}/".partition('/').last}#{opl_file}"
+ target[full_file_name] = opl.build(opl_file).to_s
+ end
+ end
+ end
+ end
+
+ def build(target_dir, public_dir, hash = self.output)
+ if Dir.exist? target_dir
+ FileUtils.rm_r target_dir
+ end
+ if Dir.exist? public_dir
+ FileUtils.copy_entry(public_dir, target_dir)
+ else
+ FileUtils.mkdir target_dir
+ end
+ hash.each do |key, val|
+ puts "key: #{key}, val: #{val}"
+ if val.is_a? String
+ file_name, type, _rb = key.to_s.split('.')
+ puts "filename: #{file_name}, type: #{type}"
+ File.open("#{target_dir}/#{file_name}.#{type}", "w") do |file|
+ file.write(val)
+ end
+ else
+ unless Dir.exist? "#{target_dir}/#{key}"
+ FileUtils.mkdir "#{target_dir}/#{key}"
+ end
+ self.build("#{target_dir}/#{key}", hash)
+ end
+ end
+ puts File.expand_path(File.dirname(__FILE__))
+ end
+
+ def output
+ @output ||= {}
+ end
+
+ def opl
+ @opl ||= Opal::Builder.new
+ end
+
+ attr_accessor :opl_path
+
+ end
+
+end
diff --git a/lib/Justicar/version.rb b/lib/Justicar/version.rb
new file mode 100644
index 0000000..36efc46
--- /dev/null
+++ b/lib/Justicar/version.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class Justicar
+ VERSION = "0.1.0"
+end
diff --git a/sig/Justicar.rbs b/sig/Justicar.rbs
new file mode 100644
index 0000000..c854480
--- /dev/null
+++ b/sig/Justicar.rbs
@@ -0,0 +1,4 @@
+module Justicar
+ VERSION: String
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
+end
diff --git a/template/Rakefile b/template/Rakefile
new file mode 100644
index 0000000..1629ff0
--- /dev/null
+++ b/template/Rakefile
@@ -0,0 +1,21 @@
+require 'Justicar'
+require 'opal-browser'
+
+desc "Build your website"
+task :build do
+ Justicar.build_source('src')
+ Justicar.build('build', 'public')
+end
+
+desc "Create a server and open your site in your browser"
+task :serve do
+ link = "http://localhost:8000/index.html"
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
+ system "start #{link}"
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin/
+ system "open #{link}"
+ elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
+ system "xdg-open #{link}"
+ end
+ `ruby -run -ehttpd build -p8000`
+end
diff --git a/template/src/index.html.rb b/template/src/index.html.rb
new file mode 100644
index 0000000..cefcf6f
--- /dev/null
+++ b/template/src/index.html.rb
@@ -0,0 +1,12 @@
+Paggio.html do
+ script type: "text/javascript", src: "script.js"
+ link rel: "stylesheet", href: "style.css"
+ h1 { "Hello world from Justicar" }
+ hr
+ h2.paggio do
+ 'Hello world from Paggio!'
+ end
+ p.paggio do
+ "This part was generated by Paggio in HTML :)"
+ end
+end
diff --git a/template/src/script.js.rb b/template/src/script.js.rb
new file mode 100644
index 0000000..0be5ef5
--- /dev/null
+++ b/template/src/script.js.rb
@@ -0,0 +1,13 @@
+require 'opal'
+require 'native'
+require 'promise'
+require 'browser/setup/full'
+
+$document.ready do
+ DOM do
+ h2.opal do
+ "Hello World from Opal!"
+ end
+ p.opal {"This part was generated by Opal from Javascript (:"}
+ end.append_to($document.body)
+end
diff --git a/template/src/style.css.rb b/template/src/style.css.rb
new file mode 100644
index 0000000..d9684e3
--- /dev/null
+++ b/template/src/style.css.rb
@@ -0,0 +1,13 @@
+Paggio.css do
+ rule '.opal' do
+ color :dodgerblue
+ end
+
+ rule '.paggio' do
+ color :goldenrod
+ end
+
+ rule 'h1' do
+ font style: :italic
+ end
+end