forked from tajmone/pml-css-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
136 lines (115 loc) · 4.67 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
=begin
================================================================================
PML CSS Playground Rakefile v1.0.0 (2024/07/17)
================================================================================
=end
require './_assets/rake/globals.rb'
# ==============================================================================
# --------------------{ P R O J E C T S E T T I N G S }---------------------
# ==============================================================================
THEMES_PRFX = "css__" # the prefix for themes folders names.
# ==============================================================================
# -------------------------------{ T A S K S }--------------------------------
# ==============================================================================
task :default => :samples
## Clean & Clobber
##################
require 'rake/clean'
CLEAN.include("**/*.html")
CLOBBER.include("#{THEMES_PRFX}*/css/*.css",
"#{THEMES_PRFX}*/css/*.css.map")
task(:clean).clear_comments
task(:clean).add_description "Delete generated HTML"
task(:clobber).clear_comments
task(:clobber).add_description "Delete compiled CSS"
## Build Samples in Place
#########################
desc "Convert samples in source dir"
task :samples
FileList["samples/*.pml"].each do |src|
html = src.ext('html')
task :samples => html
file html => src
end
## Generate Themes Tasks
########################
THEMES_DIRS = FileList["#{THEMES_PRFX}*/"]
THEMES_DIRS.each do |theme_dir|
theme = theme_dir.delete_prefix(THEMES_PRFX).chop! # Drop trailing '/'
scss_dir = "#{theme_dir}sass/"
scss_main = "#{scss_dir}styles.scss"
css_dir = "#{theme_dir}css/"
css_target = "#{css_dir}styles.css"
# Target CSS *MUST BE* "css/styles.css" because there's no other
# way to make PMLC link to it (the CLI option seem broken).
# ====================================
# Ensure the theme meets requirements!
# ====================================
err_sass = false
err_msg = ""
unless File.file?(scss_main)
err_sass = true
err_msg += " * missing Sass source: #{scss_main}\n"
end
if err_sass
PrintWarningMessage("Theme \"#{theme}\" won't be processed:\n#{err_msg}")
else
# ======================================
# Build theme task and its related tasks
# ======================================
task theme
Rake::Task[theme].add_description("Build theme: #{theme}")
task :default => theme
# ===========================
# Add Sass conversion to task
# ===========================
# For now, a single SCSS source file only!
task theme => css_target
sass_deps = FileList["#{scss_dir}**/*.scss", "#{scss_dir}**/*.css"]
file css_target => sass_deps do |t|
SassConvert(scss_main, css_target, theme)
end
# ============================
# Add PMLC conversions to task
# ============================
FileList[ "samples/*.pml", "#{theme_dir}*.pml"].each do |pml|
html_fname = pml.pathmap("%n").ext('.html')
html_f = "#{theme_dir}#{html_fname}"
task theme => html_f
file html_f => pml do
PmlConvertTheme(pml, html_f, "css/styles.css", theme)
end
end # <- shared PML files iteration
end # <- theme validation conditional branch
end # <- themes iteration
# ==============================================================================
# ---------------------------{ F U N C T I O N S }----------------------------
# ==============================================================================
def SassConvert(srcf, outf, theme)
TaskHeader "Theme: #{theme} -> Converting Sass to CSS"
puts "Target: #{outf}\n\n"
sh "sass #{srcf} #{outf}"
end
def PmlConvertTheme(srcf, outf, cssf = nil, theme)
# Converts to HTML a shared sample doc or a theme-specific doc for a theme,
# inside the theme root folder.
TaskHeader "Theme: #{theme} -> Converting Sample Doc"
puts "Source: #{srcf}\n"
puts "Target: #{outf}\n\n"
srcf_abs = File.expand_path(srcf)
cd "#{outf.pathmap("%d")}", verbose: false
sh "pmlc p2h --CSS_files \"#{cssf}\" --output #{outf.pathmap("%f")} #{srcf_abs}"
cd $repo_root, verbose: false
end
# ==============================================================================
# -------------------------------{ R U L E S }--------------------------------
# ==============================================================================
## PML Generic Conversion Rule
##############################
rule '.html' => '.pml' do |t|
TaskHeader "Converting Reference Sample Doc"
puts "Sample: #{t.source}\n\n"
cd "#{t.source.pathmap("%d")}", verbose: false
sh "pmlc p2h --output #{t.name.pathmap("%f")} #{t.source.pathmap("%f")}"
cd $repo_root, verbose: false
end