Created
July 23, 2018 17:25
-
-
Save Palleas/0321170b1f672d25630e9db9ac460719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% warning = "This file was automatically generated and should not be edited." | |
// ${warning} | |
%{ | |
import glob | |
import os | |
import re | |
}% | |
struct FixtureFile { | |
let path: String | |
} | |
struct Fixture { | |
% allStructs = [] | |
% for blog_dir in glob.glob(os.path.dirname(__file__) + "/fixtures/*"): | |
% blog_name = os.path.basename(blog_dir) | |
% struct_name = re.sub(r'\W', '', blog_name.title()) | |
% allPosts = [] | |
% allStructs.append(struct_name) | |
struct ${ struct_name } { | |
% for post in glob.glob(os.path.join(blog_dir, '_posts', '**')): | |
% post_file = os.path.basename(post) | |
% post_slug = 'post' + re.sub(r'\W', '', os.path.splitext(post_file)[0].title()) | |
%{ allPosts.append(post_slug)}% | |
static let ${post_slug} = FixtureFile( | |
path: "${blog_name}/${post_file}" | |
) | |
% end | |
static let all: [FixtureFile] = [ | |
${",\n\t\t".join(allPosts) } | |
] | |
} | |
% end | |
static var all: [FixtureFile] { | |
return | |
% for struct in allStructs: | |
${struct}.all | |
%end | |
} | |
} | |
Fixture.all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment