diff --git a/blog.html b/blog.html index 0e369c8..c4100af 100644 --- a/blog.html +++ b/blog.html @@ -1,3 +1,3 @@
just_render: $just_render_the_damn_list{}
- -$map{$do_unpack{}} - -$(do_other())[[what $rank, ]] - -$title
]] --- `list_posts @, template` expects $each{list_posts({limit = 2}), "post"}[[$post]] --- --- @tparam Page @ the calling page. --- @tparam[opt] string template a string that can contain variables and --- helpers. --- --- @treturn func the function that will be called from the template. -list_posts = (template) => (args={}) => - pages = @site\query_pages { is_a: "post" } - table.sort pages, (a, b) -> a.source > b.source - limit_or_page_count = math.min args.limit or #pages, #pages - - return for page in *pages[1, limit_or_page_count] - { :title, :id, publish_date: pub_date, :blurb } = page.meta - title = title or titleize_slug id - url = rootname page\url_for! - vals = { title: title, publish_date: pub_date, blurb: blurb, url: url } - - if template then common.fill_ignoring_pre template, vals else vals - -- replace '$if' helper function with cosmo's 'cif' html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block -- add a '$titleize' helper function @@ -113,84 +75,11 @@ html_renderer.cosmo_helpers.titleize = (slug) => titleize_slug slug files_from = (path=".") -> [Path.join path, file for file in *reverse get_files path] -test = (args={}, has_block) => - if has_block - cosmo.yield(name: "yupyup") - nil - else - common.fill_ignoring_pre [[passed in template $blove]], {blove: "haha"} - -- args._template = 2 - -- cosmo.yield(args) - -- html = @site\get_renderer "sitegen.renderers.html" - -- page\merge_meta vals - -- page.tpl_scope = page.meta - -- page.template_stack = common.Stack! - -- html\render page, assert args[1] or template, "missing html string" - listing_info = (page) -> - { :title, :id, publish_date: pub_date, :blurb } = page.meta - title = title or titleize_slug id - url = rootname page\url_for! - { title: title, publish_date: pub_date, blurb: blurb, url: url } - -list3 = (args={}, has_block) => - pages = @site\query_pages { is_a: "post" } - table.sort pages, (a, b) -> a.source > b.source - limit_or_page_count = math.min args.limit or #pages, #pages - - result = for page in *pages[1, limit_or_page_count] - vals = listing_info page - if has_block then cosmo.yield vals else common.fill_ignoring_pre template, vals - - return result unless has_block - - - - - - --- use in templates --- $list2{[[$title
]], limit = 2} --- $each{$list2({limit = 3}), "item"}[[$item]] -list2 = (args={}) => - pages = @site\query_pages { is_a: "post" } - table.sort pages, (a, b) -> a.source > b.source - limit_or_page_count = math.min args.limit or #pages, #pages - - result = for page in *pages[1, limit_or_page_count] - { :title, :id, publish_date: pub_date, :blurb } = page.meta - title = title or titleize_slug id - url = rootname page\url_for! - vals = { title: title, publish_date: pub_date, blurb: blurb, url: url } - - return if args[1] then table.concat result else result - - -one = (template) => - (arg, _has_block) => - common.fill_ignoring_pre template, arg - -two = (arg, has_block) => - common.throw_error "expecting a block" if not has_block - cosmo.yield arg - nil -- VERY IMPORTANT! - -three = (arg, has_block) => - common.throw_error "expecting a block" if not has_block - { list } = arg - cosmo.yield item for item in *list - nil -- VERY IMPORTANT! - -four1 = (template) => - (arg, _has_block) => - { list } = arg - return [common.fill_ignoring_pre template, item for item in *list] - --- four = (arg) => --- p arg - -- { list } = arg - -- p list - -- return [common.fill_ignoring_pre template, item for item in *list] + { :title, :id, publish_date: pub_date, :blurb } = page.meta + title = title or titleize_slug id + url = rootname page\url_for! + { title: title, publish_date: pub_date, blurb: blurb, url: url } get_posts = (limit) => pages = @site\query_pages { is_a: "post" } @@ -202,48 +91,6 @@ sitegen.create => @site_title = "WebDevCat.me" @app_name = "stasis" @version = "0.2.12" - @list_posts = list_posts @, template - @test = test - @list2 = list2 - @list3 = list3 - - @some_name = "robertino farterino" - @some_list = { - {say: "this"} - {say: "that"} - {say: "the other"} - } - - @one = one @, [[inline template $some_var]] - @two = two - @three = three - @four = (arg, _) => - unpack for post in *get_posts @, arg.limit - common.fill_ignoring_pre template, listing_info post - - @map = (...) => cosmo.map ... - - @do_cards = {{rank: "Ace", suit: "Spades"}, {rank: "Queen", suit: "Diamonds"}} - - @do_other = (arg, _) => - {{rank: "Ace", suit: "Spades"}, {rank: "Queen", suit: "Diamonds"}} - - @do_unpack = (arg, _) => - unpack {"three", "five", "seven"} - - --