From 8afa2971e582700a394d0d3625edd0ec6c015cd9 Mon Sep 17 00:00:00 2001 From: Vitaliy Kudryk Date: Fri, 8 Nov 2024 07:46:24 +0200 Subject: [PATCH] refactor --- .../planners/mos/pages/daily.rb | 90 +---------------- .../planners/mos/pages/daily_callable.rb | 99 +++++++++++++++++++ 2 files changed, 102 insertions(+), 87 deletions(-) create mode 100644 lib/latex_yearly_planner/planners/mos/pages/daily_callable.rb diff --git a/lib/latex_yearly_planner/planners/mos/pages/daily.rb b/lib/latex_yearly_planner/planners/mos/pages/daily.rb index 52a29086..30746430 100644 --- a/lib/latex_yearly_planner/planners/mos/pages/daily.rb +++ b/lib/latex_yearly_planner/planners/mos/pages/daily.rb @@ -5,6 +5,8 @@ module Planners module Mos module Pages class Daily < Face + include DailyCallable + attr_reader :day def set(day) @@ -75,93 +77,7 @@ def right_column end def run_methods_of(column) - params.get(column).map(&method(:send)).join(",\n") - end - - def my_gap - 'box(height: 5mm)' - end - - def my_schedule - <<~TYPST - table( - columns: 1fr, - inset: 0mm, - stroke: (_, y) => - if calc.even(y) { ( bottom: 0.4pt + black ) } - else { ( bottom: 0.4pt + gray ) }, - table.cell(stroke: (bottom: 1pt), box(height: 5mm, align(horizon, [#{i18n.t('schedule')}]))), - #{schedule_lines}, - #{params.get(:schedule_trailing_30min) ? 'box(height: 5mm)' : ''} - ) - TYPST - end - - def schedule_lines - (params.get(:schedule_from_hour)..params.get(:schedule_to_hour)).map do |hour| - "box(height: 5mm, align(horizon, [#{pretty_hour(hour)}])), box(height: 5mm)" - end.join(",\n") - end - - def pretty_hour(hour) - DateTime.parse("#{hour}:00").strftime(params.get(:schedule_strftime)) - end - - def my_little_calendar - Xtypst::LittleCalendar.new(day.month, highlight_day: day, i18n:, **params.object(:little_calendar)).to_typst - end - - def my_top_priorities - <<~TYPST - pad(bottom: 5mm, table( - columns: 1fr, - inset: 0mm, - stroke: (_, _) => (bottom: 0.4pt + black), - table.cell(stroke: (bottom: 1pt), box(height: 5mm, align(horizon, [#{i18n.t('top_priorities')}]))), - #{top_priorities_lines} - )) - TYPST - end - - def top_priorities_lines - (['box(height: 5mm, align(horizon, [$square.stroked$]))'] * params.get(:priorities_number)).join(",\n") - end - - def my_notes - <<~TYPST - stack( - dir: ttb, - spacing: 5mm, - box( - height: 5mm, width: 100%, stroke: (bottom: 1pt), - align(horizon, [#{i18n.t('daily_notes')}#{more_daily_notes}#{daily_reflect}]) - ), - box(height: #{params.get(:notes_height)}, width: 100%, rect_pattern(#{params.get(:pattern)})), - ) - TYPST - end - - def more_daily_notes - return '' unless params.section_enabled?(:daily_notes) - - " | #link(, [#{i18n.t('more_daily_notes')}])" - end - - def daily_reflect - return '' unless params.section_enabled?(:daily_reflect) - - "#h(1fr) #link(, [#{i18n.t('daily_reflect.name')}])" - end - - def my_personal_notes - <<~TYPST - stack( - dir: ttb, - spacing: 5mm, - box(height: 5mm, width: 100%, stroke: (bottom: 1pt), align(horizon, [#{i18n.t('personal_notes')}])), - box(height: #{params.get(:personal_notes_height)}, width: 100%, rect_pattern(#{params.get(:pattern)})), - ) - TYPST + params.get(column).map { |meth| send("my_#{meth}") }.join(",\n") end end end diff --git a/lib/latex_yearly_planner/planners/mos/pages/daily_callable.rb b/lib/latex_yearly_planner/planners/mos/pages/daily_callable.rb new file mode 100644 index 00000000..ebd14549 --- /dev/null +++ b/lib/latex_yearly_planner/planners/mos/pages/daily_callable.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +module LatexYearlyPlanner + module Planners + module Mos + module Pages + module DailyCallable + def my_gap + 'box(height: 5mm)' + end + + def my_schedule + <<~TYPST + table( + columns: 1fr, + inset: 0mm, + stroke: (_, y) => + if calc.even(y) { ( bottom: 0.4pt + black ) } + else { ( bottom: 0.4pt + gray ) }, + table.cell(stroke: (bottom: 1pt), box(height: 5mm, align(horizon, [#{i18n.t('schedule')}]))), + #{schedule_lines}, + #{params.get(:schedule_trailing_30min) ? 'box(height: 5mm)' : ''} + ) + TYPST + end + + def my_little_calendar + Xtypst::LittleCalendar.new(day.month, highlight_day: day, i18n:, **params.object(:little_calendar)).to_typst + end + + def my_top_priorities + <<~TYPST + pad(bottom: 5mm, table( + columns: 1fr, + inset: 0mm, + stroke: (_, _) => (bottom: 0.4pt + black), + table.cell(stroke: (bottom: 1pt), box(height: 5mm, align(horizon, [#{i18n.t('top_priorities')}]))), + #{top_priorities_lines} + )) + TYPST + end + + def my_notes + <<~TYPST + stack( + dir: ttb, + spacing: 5mm, + box( + height: 5mm, width: 100%, stroke: (bottom: 1pt), + align(horizon, [#{i18n.t('daily_notes')}#{more_daily_notes}#{daily_reflect}]) + ), + box(height: #{params.get(:notes_height)}, width: 100%, rect_pattern(#{params.get(:pattern)})), + ) + TYPST + end + + def my_personal_notes + <<~TYPST + stack( + dir: ttb, + spacing: 5mm, + box(height: 5mm, width: 100%, stroke: (bottom: 1pt), align(horizon, [#{i18n.t('personal_notes')}])), + box(height: #{params.get(:personal_notes_height)}, width: 100%, rect_pattern(#{params.get(:pattern)})), + ) + TYPST + end + + private + + def schedule_lines + (params.get(:schedule_from_hour)..params.get(:schedule_to_hour)).map do |hour| + "box(height: 5mm, align(horizon, [#{pretty_hour(hour)}])), box(height: 5mm)" + end.join(",\n") + end + + def pretty_hour(hour) + DateTime.parse("#{hour}:00").strftime(params.get(:schedule_strftime)) + end + + def top_priorities_lines + (['box(height: 5mm, align(horizon, [$square.stroked$]))'] * params.get(:priorities_number)).join(",\n") + end + + def more_daily_notes + return '' unless params.section_enabled?(:daily_notes) + + " | #link(, [#{i18n.t('more_daily_notes')}])" + end + + def daily_reflect + return '' unless params.section_enabled?(:daily_reflect) + + "#h(1fr) #link(, [#{i18n.t('daily_reflect.name')}])" + end + end + end + end + end +end