Skip to content

Commit

Permalink
Added the stuff for abbreviated copywrite
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjcoles authored and joshuacoles committed Sep 23, 2024
1 parent 2061221 commit dfd45f2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"features": {
"ghcr.io/michidk/devcontainers-features/typst:1": {}
},


// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
Expand Down
17 changes: 9 additions & 8 deletions formats/typst/entry_point.typ.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#import "helpers.typ": *
#import "@preview/cmarker:0.1.0"


#set page(
paper: "<%= page_size %>",
flipped: true,
Expand All @@ -11,7 +10,7 @@
columns: (1fr, 1fr, 1fr),
align: (left, center, right),
rows: (auto),
[© <%= Date.today.year %> Better Conversations Foundation],
[<% if style == 'abbreviated' %>© Better Conversations Foundation 2019-<%= Date.today.year %>. This work is openly licensed via CC BY-SA 4.0<% else %>© <%= Date.today.year %> Better Conversations Foundation<% end %>],
context counter(page).display("1/1",both: true),
[
<% if for_user %>
Expand All @@ -21,9 +20,13 @@
),
)


#show: flight-plan

<% if style == 'normal' %>
include "./copyright.typ"
pagebreak()
<% end %>

= Module <%= flight_plan.module_number %>: <%= flight_plan.module_title %>

== Overview
Expand Down Expand Up @@ -106,13 +109,11 @@ else { center },
#bcf-nom[<%= format_speakers(block.speaker) %>]
<% end %>
<% unless block.flipchart.nil? %>
#("<%= block.flipchart.pretty_id %>") <%= block.flipchart.inplace_comment %>

Scribed by <%= block.flipchart.pretty_scribed_by %>
<% unless block.flipchart&.inplace_section_comment.nil? %>
<%= block.flipchart&.inplace_section_comment %>
<% end %>
<% unless block.section_comment.nil? %>
<% unless block.section_comment %>
<%= block.section_comment %>
<% end %>
],
Expand Down
3 changes: 0 additions & 3 deletions formats/typst/styles.typ
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

// Begin content

include "./copyright.typ"
pagebreak()

doc
}

Expand Down
12 changes: 6 additions & 6 deletions lib/bcf/flight_plans/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def compile_typst(pdf_output_path)
end
end

def render(flight_plan, pdf_output_path, for_user: nil, page_size: "a4")
def render(flight_plan, pdf_output_path, for_user: nil, page_size: "a4", style: "normal")
output_typ = File.join(@build_context, "output.typ")

File.write(output_typ, @render_context.render_flight_plan(flight_plan, for_user: for_user, page_size: page_size))
File.write(output_typ, @render_context.render_flight_plan(flight_plan, for_user: for_user, page_size: page_size, style: style))

if @debug_print_typ
puts "[DEBUG] Typst input:"
Expand All @@ -127,9 +127,9 @@ def initialize(build_context)
end

# @return [String]
def render_flight_plan(flight_plan, for_user: nil, page_size: "a4")
def render_flight_plan(flight_plan, for_user: nil, page_size: "a4", style: "normal")
Tilt.new(root.join("entry_point.typ.erb"))
.render(self, flight_plan: flight_plan, for_user: for_user, page_size: page_size)
.render(self, flight_plan: flight_plan, for_user: for_user, page_size: page_size, style: style)
end

# TODO: It might be good to isolate these into markdown files which we then read back to avoid escaping issues.
Expand Down Expand Up @@ -159,9 +159,9 @@ def self.render_html_flight_plan(flight_plan, temp_dir)
end

class FlightPlan
def render_pdf(output_path, build_context: Dir.mktmpdir, debug_print_typ: false, for_user: nil, page_size: "a4")
def render_pdf(output_path, build_context: Dir.mktmpdir, debug_print_typ: false, for_user: nil, page_size: "a4", style: "normal")
typst_renderer = TypstRenderer.new(build_context, debug_print_typ)
typst_renderer.render(self, output_path, for_user: for_user, page_size: page_size)
typst_renderer.render(self, output_path, for_user: for_user, page_size: page_size, style: style)
end

def write_json(output_path)
Expand Down
25 changes: 23 additions & 2 deletions spec/bcf/flight_plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,29 @@
end
end

describe "migrations" do
describe "from un-versioned" do
describe 'abbreviated style' do
let(:json) { Pathname.new(__FILE__).join("..", "..", "fixtures", "module_3.json").read }

it "renders a flight plan with abbreviated style and includes BY-SA 4.0" do
flight_plan = JSON.parse(json, { create_additions: true })
tf = Tempfile.new(["abbreviated_flightplan", ".pdf"])
expect(flight_plan).to be_a(BCF::FlightPlans::FlightPlan)

expect {
flight_plan.render_pdf(tf.path, style: 'abbreviated')
}.not_to raise_error

expect(File.exist?(tf.path)).to be_truthy
expect(File.size(tf.path)).to be > 0 if File.exist?(tf.path)

# Check if the PDF contains the specific copyright text
text = PDF::Reader.new(tf.path).pages.map(&:text).join
expect(text).to include("CC BY-SA 4.0")
end
end

describe 'migrations' do
describe 'from un-versioned' do
let(:json) { Pathname.new(__FILE__).join("..", "..", "fixtures", "module_3.json").read }

it "defaults to version 0.4.4 after migration as it has no version specified" do
Expand Down

0 comments on commit dfd45f2

Please sign in to comment.