diff options
author | Carlo Landmeter <clandmeter@gmail.com> | 2015-03-17 09:43:40 +0000 |
---|---|---|
committer | Carlo Landmeter <clandmeter@gmail.com> | 2015-03-17 09:43:40 +0000 |
commit | 607080b9b771dc8503780a40fa1346f1f8b4dca9 (patch) | |
tree | 2535203ba5d5549bc7eab1999c365baca9d7dccc | |
parent | 47d6db8cbe043d2c524af68831d236080b1127f4 (diff) | |
download | aports-turbo-607080b9b771dc8503780a40fa1346f1f8b4dca9.tar.bz2 aports-turbo-607080b9b771dc8503780a40fa1346f1f8b4dca9.tar.xz |
cleanup ident
-rwxr-xr-x | aports.lua | 113 | ||||
-rw-r--r-- | tpl/contents.tpl | 18 | ||||
-rw-r--r-- | tpl/footer.tpl | 4 | ||||
-rw-r--r-- | tpl/header.tpl | 4 | ||||
-rw-r--r-- | tpl/package.tpl | 88 | ||||
-rw-r--r-- | tpl/packages.tpl | 60 |
6 files changed, 143 insertions, 144 deletions
@@ -10,87 +10,86 @@ local tpl = turbo.web.Mustache.TemplateHelper("./tpl") local ContentsRenderer = class("ContentsRenderer", turbo.web.RequestHandler) function ContentsRenderer:get() - local table = {} + local table = {} local args = { filename = self:get_argument("filename","", true), arch = self:get_argument("arch", "x86", true), } - if args.filename ~= "" then + if args.filename ~= "" then local result = QueryContents(args) if next(result) ~= nil then table.rows = result end end table.contents = true - table.filename = args.filename - table.header = tpl:render("header.tpl", table) + table.filename = args.filename + table.header = tpl:render("header.tpl", table) table.footer = tpl:render("footer.tpl", table) - local page = tpl:render(self.options, table) - self:write(page) + local page = tpl:render(self.options, table) + self:write(page) end local PackagesRenderer = class("PackagesRenderer", turbo.web.RequestHandler) function PackagesRenderer:get() - local table = {} + local table = {} local args = { package = self:get_argument("package","", true) } - if args.package == "" then - args.package = "%" - end - local result = QueryPackages(args) - if next(result) ~= nil then - table.rows = result - end + if args.package == "" then + args.package = "%" + end + local result = QueryPackages(args) + if next(result) ~= nil then + table.rows = result + end table.packages = true - table.header = tpl:render("header.tpl", table) - table.footer = tpl:render("footer.tpl", table) - local page = tpl:render(self.options, table) - self:write(page) + table.header = tpl:render("header.tpl", table) + table.footer = tpl:render("footer.tpl", table) + local page = tpl:render(self.options, table) + self:write(page) print(inspect(table)) end local PackageRenderer = class("PackageRenderer", turbo.web.RequestHandler) function PackageRenderer:get(arch, pkgname) - local fields = {} - local table = {} - fields.arch = arch - fields.pkgname = pkgname - result = QueryPackage(fields) - - if result ~= nil then - table = result - for k in pairs (table) do + local fields = {} + local table = {} + fields.arch = arch + fields.pkgname = pkgname + result = QueryPackage(fields) + if result ~= nil then + table = result + for k in pairs (table) do if table[k] == "" then table[k] = nil end end - end - table.header = tpl:render("header.tpl") - table.footer = tpl:render("footer.tpl") - local page = tpl:render(self.options, table) - self:write(page) + end + table.header = tpl:render("header.tpl") + table.footer = tpl:render("footer.tpl") + local page = tpl:render(self.options, table) + self:write(page) end function QueryContents(terms) - require('DBI') - local dbh = assert(DBI.Connect('SQLite3', 'db/filelist.db')) - local sth = assert(dbh:prepare('select * from filelist where file like ? and arch like ? limit 100')) - sth:execute(terms.filename, terms.arch) - local r = {} - for row in sth:rows(true) do - r[#r + 1] = { - file = "/" .. row.path .. "/" .. row.file, - pkgname = row.pkgname, - repo = row.repo, - arch = row.arch, - } - end - return r - + require('DBI') + local dbh = assert(DBI.Connect('SQLite3', 'db/filelist.db')) + local sth = assert(dbh:prepare('select * from filelist where file like ? and arch like ? limit 100')) + sth:execute(terms.filename, terms.arch) + local r = {} + for row in sth:rows(true) do + r[#r + 1] = { + file = "/" .. row.path .. "/" .. row.file, + pkgname = row.pkgname, + repo = row.repo, + arch = row.arch, + } + end + return r end + function QueryPackages(terms) require('DBI') local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) @@ -114,21 +113,21 @@ function QueryPackages(terms) end function QueryPackage(fields) - require('DBI') - local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) + require('DBI') + local dbh = assert(DBI.Connect('SQLite3', 'db/apkindex.db')) local sth = assert(dbh:prepare('select *, datetime(build_time, \'unixepoch\') as build_time from apkindex where name like ? and arch like ? limit 1')) - sth:execute(fields.pkgname, fields.arch) - local r = {} - r = sth:fetch(true) + sth:execute(fields.pkgname, fields.arch) + local r = {} + r = sth:fetch(true) print(inspect(r)) - return r + return r end turbo.web.Application({ - {"^/$", turbo.web.RedirectHandler, "/packages"}, - {"^/contents$", ContentsRenderer, "contents.tpl"}, + {"^/$", turbo.web.RedirectHandler, "/packages"}, + {"^/contents$", ContentsRenderer, "contents.tpl"}, {"^/packages$", PackagesRenderer, "packages.tpl"}, - {"^/package/(.*)/(.*)$", PackageRenderer, "package.tpl"}, - {"/assets/(.*)$", turbo.web.StaticFileHandler, "assets/"}, + {"^/package/(.*)/(.*)$", PackageRenderer, "package.tpl"}, + {"/assets/(.*)$", turbo.web.StaticFileHandler, "assets/"}, }):listen(8888) turbo.ioloop.instance():start() diff --git a/tpl/contents.tpl b/tpl/contents.tpl index dc4fe92..f3084d8 100644 --- a/tpl/contents.tpl +++ b/tpl/contents.tpl @@ -8,14 +8,14 @@ <label for="filename">Filename</label> <input type="text" class="form-control" id="filename" name="filename" value="{{{filename}}}"> </div> - <div class="form-group"> + <div class="form-group"> <label for="arch">Architecture</label> - <select name="arch" class="form-control" id="arch"> + <select name="arch" class="form-control" id="arch"> <option>x86</option> <option>x86_64</option> <option>armhf</option> </select> - </div> + </div> <button type="submit" class="btn btn-primary">Search</button> </form> </div> @@ -23,15 +23,15 @@ <table class="table table-striped table-bordered table-condensed" data-toggle="table"> <tr> <th>File</th> - <th>Package name</th> - <th>Repository</th> - <th>Architecture</th> + <th>Package name</th> + <th>Repository</th> + <th>Architecture</th> </tr>{{#rows}} <tr> <td>{{{file}}}</td> - <td>{{{pkgname}}}</td> - <td>{{{repo}}}</td> - <td>{{{arch}}}</td> + <td>{{{pkgname}}}</td> + <td>{{{repo}}}</td> + <td>{{{arch}}}</td> </tr>{{/rows}} {{{^rows}}} <tr> diff --git a/tpl/footer.tpl b/tpl/footer.tpl index 60e689e..2d29c22 100644 --- a/tpl/footer.tpl +++ b/tpl/footer.tpl @@ -1,3 +1,3 @@ - <footer>© Copyright 2014 Alpine Linux Development Team all rights reserved | <a href="http://www.alpinelinux.org/privacy-policy.html">Privacy Policy</a></footer> - </body> + <footer>© Copyright 2014 Alpine Linux Development Team all rights reserved | <a href="http://www.alpinelinux.org/privacy-policy.html">Privacy Policy</a></footer> + </body> </html> diff --git a/tpl/header.tpl b/tpl/header.tpl index fdfdb67..072aff9 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -25,14 +25,14 @@ <a href="/"><img id="logo" src="/assets/alpinelinux-logo.svg" alt="Alpine Linux logo" /></a> <div id="pagenav"> <nav> - {{#packages}} + {{#packages}} <a href="/packages" class="active">Packages</a> {{/packages}} {{^packages}} <a href="/packages">Packages</a> {{/packages}} {{#contents}} - <a href="/contents" class="active" class="">Contents</a> + <a href="/contents" class="active" class="">Contents</a> {{/contents}} {{^contents}} <a href="/contents" class="">Contents</a> diff --git a/tpl/package.tpl b/tpl/package.tpl index e25110f..e6e35a2 100644 --- a/tpl/package.tpl +++ b/tpl/package.tpl @@ -4,53 +4,53 @@ <div class="panel-heading">Package details</div> <div class="panel-body"> </div> - <table class="table table-striped table-bordered table-condensed" id="package"> - {{#name}} - <tr> - <th>Name</th> - <td title="{{{desc}}}"><a href="/package/{{{name}}}">{{{name}}}</a></td> - </tr> - <tr> - <th>Version</th> - <td>{{{version}}}</td> - </tr> - <tr> - <th>Project</th> - <td><a href="{{{url}}}">URL</a></td> - </tr> - <tr> - <th>Licence</th> - <td>{{{lic}}}</td> - </tr> - <tr> - <th>Architecture</th> - <td>{{{arch}}}</td> - </tr> - <tr> - <th>Repository</th> - <td>Repository</td> - </tr> - <tr> - <th>Maintainer</th> - <td>{{{maintainer}}}</td> - </tr> - <tr> - <th>Build date</th> - <td>{{{build_time}}}</td> - </tr> + <table class="table table-striped table-bordered table-condensed" id="package"> + {{#name}} + <tr> + <th>Name</th> + <td title="{{{desc}}}"><a href="/package/{{{name}}}">{{{name}}}</a></td> + </tr> + <tr> + <th>Version</th> + <td>{{{version}}}</td> + </tr> + <tr> + <th>Project</th> + <td><a href="{{{url}}}">URL</a></td> + </tr> + <tr> + <th>Licence</th> + <td>{{{lic}}}</td> + </tr> + <tr> + <th>Architecture</th> + <td>{{{arch}}}</td> + </tr> + <tr> + <th>Repository</th> + <td>Repository</td> + </tr> + <tr> + <th>Maintainer</th> + <td>{{{maintainer}}}</td> + </tr> + <tr> + <th>Build date</th> + <td>{{{build_time}}}</td> + </tr> {{#install_if}} <tr> - <th>Install if</th> - <td>{{{install_if}}}</td> - </tr> + <th>Install if</th> + <td>{{{install_if}}}</td> + </tr> {{/install_if}} - {{/name}} - {{^name}} - <tr> - <td>This package does not exist!</td> - </tr> - {{/name}} - </table> + {{/name}} + {{^name}} + <tr> + <td>This package does not exist!</td> + </tr> + {{/name}} + </table> </div> </div> {{{footer}}} diff --git a/tpl/packages.tpl b/tpl/packages.tpl index 9027858..4008ff0 100644 --- a/tpl/packages.tpl +++ b/tpl/packages.tpl @@ -8,44 +8,44 @@ <label for="package">Package name</label> <input type="text" class="form-control" id="package" name="package" value="{{{package}}}"> </div> - <div class="form-group"> + <div class="form-group"> <label for="arch">Architecture</label> - <select name="arch" class="form-control" id="arch"> + <select name="arch" class="form-control" id="arch"> <option>x86</option> <option>x86_64</option> <option>armhf</option> </select> - </div> + </div> <button type="submit" class="btn btn-primary">Search</button> </form> </div> - <table class="table table-striped table-bordered table-condensed"> - <tr> - <th>Package</th> - <th>Version</th> - <th>Project</th> - <th>Licence</th> - <th>Architecture</th> - <th>Repository</th> - <th>Maintainer</th> - <th>Build date</th> - </tr>{{#rows}} - <tr> - <td class="package" title="{{{desc}}}"><a href="/package/{{{arch}}}/{{{package}}}">{{{package}}}</a></td> - <td class="version">{{{version}}}</td> - <td class="url"><a href="{{{project}}}">URL</a></td> - <td class="license">{{{license}}}</td> - <td class="arch">{{{arch}}}</td> - <td class="repo">{{{repo}}}</td> - <td class="maintainer">{{{maintainer}}}</td> - <td class="bdate">{{{bdate}}}</td> - </tr>{{/rows}} - {{{^rows}}} - <tr> - <td colspan="8">No item found...</td> - </tr> - {{{/rows}}} - </table> + <table class="table table-striped table-bordered table-condensed"> + <tr> + <th>Package</th> + <th>Version</th> + <th>Project</th> + <th>Licence</th> + <th>Architecture</th> + <th>Repository</th> + <th>Maintainer</th> + <th>Build date</th> + </tr>{{#rows}} + <tr> + <td class="package" title="{{{desc}}}"><a href="/package/{{{arch}}}/{{{package}}}">{{{package}}}</a></td> + <td class="version">{{{version}}}</td> + <td class="url"><a href="{{{project}}}">URL</a></td> + <td class="license">{{{license}}}</td> + <td class="arch">{{{arch}}}</td> + <td class="repo">{{{repo}}}</td> + <td class="maintainer">{{{maintainer}}}</td> + <td class="bdate">{{{bdate}}}</td> + </tr>{{/rows}} + {{{^rows}}} + <tr> + <td colspan="8">No item found...</td> + </tr> + {{{/rows}}} + </table> </div> </div> {{{footer}}} |