diff options
author | mms <git@sapka.me> | 2025-01-05 22:34:55 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2025-01-05 22:34:55 +0100 |
commit | bfd8209ad0d80b5027bea8a1a095dadc8bffdc61 (patch) | |
tree | 1d4ec6d63dd3b4a1f788ec340a0fba3cd48b3dea /new/lib | |
parent | 628fcf941c322dd0ed24a643c58394392484740e (diff) |
Diffstat (limited to 'new/lib')
-rw-r--r-- | new/lib/crys.rb | 4 | ||||
-rw-r--r-- | new/lib/crys/_code_processor.rb (renamed from new/lib/crys/code_processor.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_default_data.rb (renamed from new/lib/crys/default_data.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_file_watcher.rb (renamed from new/lib/crys/file_watcher.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_listing.rb (renamed from new/lib/crys/listing.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_new_file.rb (renamed from new/lib/crys/new_file.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_page_from_erb.rb (renamed from new/lib/crys/page_from_erb.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_page_from_org.rb (renamed from new/lib/crys/page_from_org.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/_resource_from_css.rb (renamed from new/lib/crys/resource_from_css.rb) | 0 | ||||
-rw-r--r-- | new/lib/crys/builder.rb | 50 | ||||
-rw-r--r-- | new/lib/crys/image_processor.rb | 20 | ||||
-rw-r--r-- | new/lib/crys/processors/common_functions.rb | 31 | ||||
-rw-r--r-- | new/lib/crys/processors/common_parts.rb | 20 | ||||
-rw-r--r-- | new/lib/crys/processors/html_processor.rb | 38 | ||||
-rw-r--r-- | new/lib/crys/renderer.rb | 32 |
15 files changed, 161 insertions, 34 deletions
diff --git a/new/lib/crys.rb b/new/lib/crys.rb index 333fcfb..68542a0 100644 --- a/new/lib/crys.rb +++ b/new/lib/crys.rb @@ -1,4 +1,8 @@ +require_relative "crys/processors/html_processor.rb" + require_relative "crys/server.rb" +require_relative "crys/builder.rb" +require_relative "crys/image_processor.rb" module Crys end diff --git a/new/lib/crys/code_processor.rb b/new/lib/crys/_code_processor.rb index e69de29..e69de29 100644 --- a/new/lib/crys/code_processor.rb +++ b/new/lib/crys/_code_processor.rb diff --git a/new/lib/crys/default_data.rb b/new/lib/crys/_default_data.rb index 8333669..8333669 100644 --- a/new/lib/crys/default_data.rb +++ b/new/lib/crys/_default_data.rb diff --git a/new/lib/crys/file_watcher.rb b/new/lib/crys/_file_watcher.rb index e69de29..e69de29 100644 --- a/new/lib/crys/file_watcher.rb +++ b/new/lib/crys/_file_watcher.rb diff --git a/new/lib/crys/listing.rb b/new/lib/crys/_listing.rb index e69de29..e69de29 100644 --- a/new/lib/crys/listing.rb +++ b/new/lib/crys/_listing.rb diff --git a/new/lib/crys/new_file.rb b/new/lib/crys/_new_file.rb index e69de29..e69de29 100644 --- a/new/lib/crys/new_file.rb +++ b/new/lib/crys/_new_file.rb diff --git a/new/lib/crys/page_from_erb.rb b/new/lib/crys/_page_from_erb.rb index e69de29..e69de29 100644 --- a/new/lib/crys/page_from_erb.rb +++ b/new/lib/crys/_page_from_erb.rb diff --git a/new/lib/crys/page_from_org.rb b/new/lib/crys/_page_from_org.rb index e69de29..e69de29 100644 --- a/new/lib/crys/page_from_org.rb +++ b/new/lib/crys/_page_from_org.rb diff --git a/new/lib/crys/resource_from_css.rb b/new/lib/crys/_resource_from_css.rb index e69de29..e69de29 100644 --- a/new/lib/crys/resource_from_css.rb +++ b/new/lib/crys/_resource_from_css.rb diff --git a/new/lib/crys/builder.rb b/new/lib/crys/builder.rb new file mode 100644 index 0000000..a3f55b1 --- /dev/null +++ b/new/lib/crys/builder.rb @@ -0,0 +1,50 @@ + +module Crys + class Builder + + + def initialize(file_path:, output_dir:, image_dir:) + @file_path = file_path + @output_dir = output_dir + @processor = processor_class.new(file_path: file_path, image_dir: image_dir) + + end + + def build + process_html + process_assets + end + + private + + attr_reader :file_path, :output_dir, :processor + + def process_assets + processor.assets.each do |asset| + output_path = output_dir + "/" + asset.relative_path + File.open(output_path, 'w') { |file| file.write(asset.processed_asset) } + end + end + + def process_html + html = processor.to_html + filename = processor.filename + output_path = output_dir + "/" + filename + + File.open(output_path, 'w') { |file| file.write(html) } + end + + def processor_class + case file_path + when /html.erb$/ + html_processor + else + raise StandardError.new("No processor for #{file_path}") + end + end + + def html_processor + Crys::HtmlProcessor + end + end +end diff --git a/new/lib/crys/image_processor.rb b/new/lib/crys/image_processor.rb index 1a33d04..b7e2fd6 100644 --- a/new/lib/crys/image_processor.rb +++ b/new/lib/crys/image_processor.rb @@ -1,10 +1,26 @@ module Crys class ImageProcessor - def initialize(path:, width:, height:, format:) + def initialize(path:, filename:, width: :auto) + @path = path + @filename = filename + @file = File.read(path) end - def path + def relative_path + filename + end + + def filename + filename + end + def processed_asset + file.to_s end + + private + + attr_reader :path, :filename, :file + end end diff --git a/new/lib/crys/processors/common_functions.rb b/new/lib/crys/processors/common_functions.rb new file mode 100644 index 0000000..f33c768 --- /dev/null +++ b/new/lib/crys/processors/common_functions.rb @@ -0,0 +1,31 @@ +require 'rss' + +module Crys + module CommonFunctions + def project_root + "#{File.dirname(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))}" + end + + def process_image(file:, width: :auto) + full_path = image_dir + "/" + file + + image = ::Crys::ImageProcessor.new(path: full_path, filename: file, width: width) + assets << image + + image + end + + def fetch_rss(url: nil, name: nil) + if name + path = case name + when :main + "/public/index.xml" + end + + rss = File.read(project_root + path) + end + + RSS::Parser.parse(rss) + end + end +end diff --git a/new/lib/crys/processors/common_parts.rb b/new/lib/crys/processors/common_parts.rb new file mode 100644 index 0000000..1dbf6d8 --- /dev/null +++ b/new/lib/crys/processors/common_parts.rb @@ -0,0 +1,20 @@ +module Crys + module CommonParts + def webbutton(file:, url:, alt:) + full_path = image_dir + "/buttons/" + file + + image = ::Crys::ImageProcessor.new(path: full_path, filename: file, width: 88) + assets << image + + code = ERB.new <<-EOF +<a href="<%=url%>"> +<img src="<%=image.relative_path%>" width="88" height="31" class="webbutton" alt="<%=alt%>"> +</a> +EOF + + code.result(binding) + + end + + end +end diff --git a/new/lib/crys/processors/html_processor.rb b/new/lib/crys/processors/html_processor.rb new file mode 100644 index 0000000..d5ea73d --- /dev/null +++ b/new/lib/crys/processors/html_processor.rb @@ -0,0 +1,38 @@ +require 'erb' +require_relative "common_functions" +require_relative "common_parts" + +module Crys + class HtmlProcessor + + include CommonFunctions + include CommonParts + + def initialize(file_path:, image_dir:) + @file_path = file_path + @image_dir = image_dir + @assets = [] + end + + def to_html + html_file = ERB.new(File.read(file_path)) + html_file.result(local_binding) + end + + + def filename + file_path.scan(/.*\/(.*)\.erb/).flatten.first + end + + attr_reader :assets + + private + + attr_reader :file_path, :image_dir + attr_writer :assets + + def local_binding + local_binding ||= binding.clone + end + end +end diff --git a/new/lib/crys/renderer.rb b/new/lib/crys/renderer.rb deleted file mode 100644 index c490330..0000000 --- a/new/lib/crys/renderer.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'erb' -require 'pry' - -module Crys - module Splash - class Theme - PARENT_DIR = File.expand_path(".", Dir.pwd) - - def render - template = ERB.new(File.read(PARENT_DIR + "/theme/" + self.class::PAGE)) - template.result(local_binding) - end - - def body - self.class::BODY.result(local_binding) - end - - private - - attr_accessor :template, :data - - def local_binding - local_binding = binding.clone - self.class::DATA.each do |k, v| - local_binding.local_variable_set(k,v) - end - local_binding - - end - end - end -end |