diff --git a/.direnv/flake-profile b/.direnv/flake-profile index 0c05709..e289079 120000 --- a/.direnv/flake-profile +++ b/.direnv/flake-profile @@ -1 +1 @@ -flake-profile-1-link \ No newline at end of file +flake-profile-4-link \ No newline at end of file diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link deleted file mode 120000 index f43de35..0000000 --- a/.direnv/flake-profile-1-link +++ /dev/null @@ -1 +0,0 @@ -/nix/store/rjd1hg7kfh3k6hvjb3inh5d6vq22rldx-nix-shell-env \ No newline at end of file diff --git a/.direnv/flake-profile-4-link b/.direnv/flake-profile-4-link new file mode 120000 index 0000000..9a52432 --- /dev/null +++ b/.direnv/flake-profile-4-link @@ -0,0 +1 @@ +/nix/store/w94drfg1lkr1jlkbj820c7bcfvabzycy-nix-shell-env \ No newline at end of file diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 0de858b..5b59467 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -23,6 +23,16 @@ jobs: with: ruby-version: '3.3.5' bundler-cache: true + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get install libfuse2 + mkdir -p "$HOME/.local/bin" + curl -O 'https://imagemagick.org/archive/binaries/magick' + chmod u+x magick + mv magick "$HOME/.local/bin" + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + - name: Verify dependencies + run: magick -version - name: Set up database schema working-directory: ./cdmm run: bundle install && bin/rails db:schema:load && bin/rails db:migrate diff --git a/.gitignore b/.gitignore index a105d18..c90addd 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ /cdmm/app/assets/builds/* !/cdmm/app/assets/builds/.keep + +.DS_Store \ No newline at end of file diff --git a/cdmm/Gemfile b/cdmm/Gemfile index 2d100ee..ba33942 100644 --- a/cdmm/Gemfile +++ b/cdmm/Gemfile @@ -35,6 +35,8 @@ gem "bootsnap", require: false gem "meta-tags" +gem 'rmagick' + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" diff --git a/cdmm/Gemfile.lock b/cdmm/Gemfile.lock index 257cdc2..4f1569f 100644 --- a/cdmm/Gemfile.lock +++ b/cdmm/Gemfile.lock @@ -168,10 +168,12 @@ GEM racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) + observer (0.1.2) parallel (1.26.3) parser (3.3.5.0) ast (~> 2.4.1) racc + pkg-config (1.5.7) psych (5.1.2) stringio public_suffix (6.0.1) @@ -231,6 +233,9 @@ GEM reline (0.5.10) io-console (~> 0.5) rexml (3.3.8) + rmagick (6.0.1) + observer (~> 0.1) + pkg-config (~> 1.4) rubocop (1.67.0) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -347,6 +352,7 @@ DEPENDENCIES puma (>= 5.0) rails (~> 7.2.1, >= 7.2.1.1) rails_live_reload + rmagick rubocop-rails-omakase selenium-webdriver sprockets-rails diff --git a/cdmm/app/assets/config/manifest.js b/cdmm/app/assets/config/manifest.js index b06fc42..a9f221d 100644 --- a/cdmm/app/assets/config/manifest.js +++ b/cdmm/app/assets/config/manifest.js @@ -1,5 +1,6 @@ //= link_tree ../images +//= link_directory ../fonts .ttf //= link_directory ../stylesheets .css //= link_tree ../../javascript .js //= link_tree ../../../vendor/javascript .js -//= link_tree ../builds +//= link_tree ../builds \ No newline at end of file diff --git a/cdmm/app/assets/fonts/Prompt-Bold.ttf b/cdmm/app/assets/fonts/Prompt-Bold.ttf new file mode 100644 index 0000000..ae5e7b9 Binary files /dev/null and b/cdmm/app/assets/fonts/Prompt-Bold.ttf differ diff --git a/cdmm/app/assets/fonts/Prompt-Regular.ttf b/cdmm/app/assets/fonts/Prompt-Regular.ttf new file mode 100644 index 0000000..278e96c Binary files /dev/null and b/cdmm/app/assets/fonts/Prompt-Regular.ttf differ diff --git a/cdmm/app/assets/images/preview-background.png b/cdmm/app/assets/images/preview-background.png new file mode 100644 index 0000000..d08f109 Binary files /dev/null and b/cdmm/app/assets/images/preview-background.png differ diff --git a/cdmm/app/controllers/cdmm_controller.rb b/cdmm/app/controllers/cdmm_controller.rb index f72fe4d..962454e 100644 --- a/cdmm/app/controllers/cdmm_controller.rb +++ b/cdmm/app/controllers/cdmm_controller.rb @@ -1,3 +1,5 @@ +require 'rmagick' + class CdmmController < ApplicationController include ApplicationHelper # Viewing @@ -13,6 +15,88 @@ class CdmmController < ApplicationController # Purging # draft form will be purged regularly + def preview + options = { + :dimension => { + :width => 820, + :height => 320 + }, + :border_bar => { + :height => 15, + :color => "#336699" + }, + :padding => { + :left => 50, + :top => 50 + }, + :title => { + :size => 32, + :font => Rails.root.join('app', 'assets', 'fonts', 'Prompt-Bold.ttf').to_s, + :color => "black" + }, + :subtitle => { + :size => 24, + :font => Rails.root.join('app', 'assets', 'fonts', 'Prompt-Regular.ttf').to_s, + :color => "#505050" + }, + :background => { + :image => Rails.root.join('app', 'assets', 'images', 'preview-background.png').to_s, + } + } + + + @form = Evaluation.find_by(form_key: params[:form_key]) + if @form + image = Magick::Image.new(options[:dimension][:width], options[:dimension][:height]) { |options| options.background_color = 'white' } + draw = Magick::Draw.new + + # Draw background + background_image = Magick::Image.read(options[:background][:image]).first + background_image.resize!(0.40) + + image = image.composite(background_image, Magick::SouthEastGravity, Magick::OverCompositeOp) + + # Draw top border + draw.fill(options[:border_bar][:color]) + draw.rectangle(0, 0, options[:dimension][:width], options[:border_bar][:height]) + draw.draw(image) + + # Draw title + draw.font_weight = Magick::BoldWeight + draw.pointsize = options[:title][:size] + draw.gravity = Magick::NorthWestGravity + draw.annotate(image, + options[:dimension][:width] - (options[:padding][:left] * 2), + options[:dimension][:height] - (options[:padding][:top] * 2), + options[:padding][:left], + options[:padding][:top], + @form[:title]) do |opts| + opts.font = options[:title][:font] + opts.fill = options[:title][:color] + end + + # Draw subtitle + draw.font_weight = Magick::NormalWeight + draw.pointsize = options[:subtitle][:size] + draw.gravity = Magick::NorthWestGravity + draw.annotate(image, + options[:dimension][:width] - (options[:padding][:left] * 2), + options[:dimension][:height] - (options[:padding][:top] * 2), + options[:padding][:left], + options[:padding][:top] + (options[:title][:size] * 1.3), + "Continuous Delivery Maturity Model") do |opts| + opts.font = options[:subtitle][:font] + opts.fill = options[:subtitle][:color] + end + + image.format = 'PNG' + + send_data image.to_blob, type: 'image/png', disposition: 'inline' + else + render_not_found + end + end + def purge deleted_rows = Evaluation.where(:form_status => :draft, :created_at => ...6.hours.ago) deleted_count = deleted_rows.count diff --git a/cdmm/config/routes.rb b/cdmm/config/routes.rb index a0b88e1..2b7ae6e 100644 --- a/cdmm/config/routes.rb +++ b/cdmm/config/routes.rb @@ -5,6 +5,7 @@ get "cdmm" => "cdmm#index", as: :evaluation_index post "cdmm" => "cdmm#save", as: :evaluation_save get "cdmm/:form_key" => "cdmm#show", as: :evaluation_show + get "cdmm/:form_key/preview" => "cdmm#preview" get "schedule/purge" => "cdmm#purge" # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. diff --git a/flake.nix b/flake.nix index 73cba5d..207b6ae 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ ${system}.default = nixpkgs.legacyPackages.${system}.mkShell { buildInputs = with nixpkgs.legacyPackages.${system}; [ ruby_3_3 + imagemagick # playwright # playwright-driver ];