Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: resources/slides_utils.lua

Issue 692543004: break transitions into separate file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « resources/slides_transitions.lua ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function tostr(t) 1 function tostr(t)
2 local str = "" 2 local str = ""
3 for k, v in next, t do 3 for k, v in next, t do
4 if #str > 0 then 4 if #str > 0 then
5 str = str .. ", " 5 str = str .. ", "
6 end 6 end
7 if type(k) == "number" then 7 if type(k) == "number" then
8 str = str .. "[" .. k .. "] = " 8 str = str .. "[" .. k .. "] = "
9 else 9 else
10 str = str .. tostring(k) .. " = " 10 str = str .. tostring(k) .. " = "
(...skipping 11 matching lines...) Expand all
22 22
23 function trim_ws(s) 23 function trim_ws(s)
24 return s:match("^%s*(.*)") 24 return s:match("^%s*(.*)")
25 end 25 end
26 26
27 function count_hypens(s) 27 function count_hypens(s)
28 local leftover = s:match("^-*(.*)") 28 local leftover = s:match("^-*(.*)")
29 return string.len(s) - string.len(leftover) 29 return string.len(s) - string.len(leftover)
30 end 30 end
31 31
32 function parse_file(file)
33 local slides = {}
34 local block = {}
35
36 for line in file:lines() do
37 local s = trim_ws(line)
38 if #s == 0 then -- done with a block
39 if #block > 0 then
40 slides[#slides + 1] = block
41 block = {}
42 end
43 else
44 local n = count_hypens(s)
45 block[#block + 1] = {
46 indent = n,
47 text = trim_ws(s:sub(n + 1, -1))
48 }
49 end
50 end
51 return slides
52 end
53
54 function pretty_print_slide(slide) 32 function pretty_print_slide(slide)
55 io.write("{\n") 33 io.write("{\n")
34 if slide.transition then
35 io.write(" transition = \"", slide.transition, "\",\n")
36 end
56 for i = 1, #slide do 37 for i = 1, #slide do
57 local node = slide[i] 38 local node = slide[i]
58 for j = 0, node.indent do 39 for j = 0, node.indent do
59 io.write(" ") 40 io.write(" ")
60 end 41 end
61 io.write("{ ") 42 io.write("{ ")
62 io.write(tostr(node)) 43 io.write(tostr(node))
63 io.write(" },\n") 44 io.write(" },\n")
64 end 45 end
65 io.write("},\n") 46 io.write("},\n")
66 end 47 end
67 48
68 function pretty_print_slides(slides) 49 function pretty_print_slides(slides)
69 io.write("gSlides = {\n") 50 io.write("gSlides = {\n")
70 for i = 1, #slides do 51 for i = 1, #slides do
71 pretty_print_slide(slides[i]) 52 pretty_print_slide(slides[i])
72 end 53 end
73 io.write("}\n") 54 io.write("}\n")
74 end 55 end
75 56
57 function parse_transition_type(s)
58 return s:match("^<%s*transition%s*=%s*(%a+)%s*>$")
59 end
60
61 function parse_file(file)
62 local slides = {}
63 local block = {}
64
65 for line in file:lines() do
66 local s = trim_ws(line)
67 if #s == 0 then -- done with a block
68 if #block > 0 then
69 slides[#slides + 1] = block
70 block = {}
71 end
72 else
73 local transition_type = parse_transition_type(s)
74 if transition_type then
75 block["transition"] = transition_type
76 else
77 local n = count_hypens(s)
78 block[#block + 1] = {
79 indent = n,
80 text = trim_ws(s:sub(n + 1, -1))
81 }
82 end
83 end
84 end
85 -- pretty_print_slides(slides)
86 return slides
87 end
88
OLDNEW
« no previous file with comments | « resources/slides_transitions.lua ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698