You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/index.cr
+25-23Lines changed: 25 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -85,64 +85,66 @@ module Fluence
85
85
self
86
86
end
87
87
88
-
# Returns T from index, raises if missing.
89
-
# There is generally little use from sending a T as argument to retrieve the same T back, so this should be used just as a true-or-raise check for existence of pages.
# There is generally little use from sending a T as argument to retrieve the same T back, so this should be used just as a true-or-nil check for existence of pages.
100
92
def[]?(page : T) : T?
101
-
@entries[page.name]?
93
+
::File.exists?(page.path) ? page : nil
102
94
end
103
-
# Returns T from index, nil if missing.
95
+
104
96
def[]?(name : String) : T?
105
-
@entries[name]?
97
+
page =T.new name
98
+
self[page]?
99
+
end
100
+
def[](name : String) : T
101
+
page =T.new name
102
+
self[page]
106
103
end
107
104
108
-
# Adds a new `T` into the index. This is a memory-only operation and does not sync new index contents to disk.
109
-
# Only index is affected, not the actual file.
105
+
# Writes page to disk. Does not commit to Git.
110
106
defadd(page : T)
111
-
@entries[page.name] = page
107
+
page.jail!
108
+
page.content.try do |content| ::File.write page.path, content end
112
109
self
113
110
end
114
111
# Adds a new `T` into the index. This operation syncs new index contents to disk.
115
112
defadd!(page : T)
116
113
add page
117
-
save!
114
+
#commit! user, "update"
118
115
self
119
116
end
120
117
121
118
# Removes a T from Index. This is a memory-only operation and does not sync new index contents to disk.
122
119
# Recursive deletion is not handled here for now.
123
120
defdelete(page : T)
124
-
@entries.delete page.name
121
+
page.jail!
122
+
::File.delete page.path
125
123
self
126
124
end
127
125
# Deletes a page from index. This operation syncs new index contents to disk.
128
126
# Recursive deletion is not handled here for now.
129
127
defdelete!(page : T)
130
128
delete page
131
-
save!
129
+
#commit! user, "delete"
132
130
self
133
131
end
134
132
135
133
# Renames `T` in index. This is a memory-only operation and does not sync new contents to disk.
0 commit comments