Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kudrykv committed Nov 8, 2024
1 parent 2c9bfda commit 8afa297
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 87 deletions.
90 changes: 3 additions & 87 deletions lib/latex_yearly_planner/planners/mos/pages/daily.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Planners
module Mos
module Pages
class Daily < Face
include DailyCallable

attr_reader :day

def set(day)
Expand Down Expand Up @@ -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(<mdn-#{day.id}>, [#{i18n.t('more_daily_notes')}])"
end

def daily_reflect
return '' unless params.section_enabled?(:daily_reflect)

"#h(1fr) #link(<dr-#{day.id}>, [#{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
Expand Down
99 changes: 99 additions & 0 deletions lib/latex_yearly_planner/planners/mos/pages/daily_callable.rb
Original file line number Diff line number Diff line change
@@ -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(<mdn-#{day.id}>, [#{i18n.t('more_daily_notes')}])"
end

def daily_reflect
return '' unless params.section_enabled?(:daily_reflect)

"#h(1fr) #link(<dr-#{day.id}>, [#{i18n.t('daily_reflect.name')}])"
end
end
end
end
end
end

0 comments on commit 8afa297

Please sign in to comment.