您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
14 年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. verbose = False
  2. import os
  3. class Project:
  4. """
  5. Build a project
  6. Make files::
  7. index.html
  8. assets/template.html
  9. assets/js/core.min.js
  10. assets/timestamps.json
  11. """
  12. def __init__(self):
  13. """
  14. load libraries
  15. """
  16. from py.build.bundle import Bundle
  17. self.bundle = Bundle()
  18. def getversion(self):
  19. """get from version.num file and increment it"""
  20. if os.path.exists('version.num'):
  21. with open('version.num', 'r') as vfile:
  22. self.version = int(vfile.read()) + 1
  23. else:
  24. self.version = 1
  25. with open('version.num', 'w') as vfile:
  26. vfile.write(str(self.version))
  27. return self.version
  28. def boot(self):
  29. """
  30. returns bootstrap js
  31. """
  32. import json
  33. corejs = open('lib/js/core.min.js', 'r')
  34. boot = ('window._version_number="%s"' % str(self.getversion())) + \
  35. '\n' + corejs.read()
  36. corejs.close()
  37. return boot
  38. def render_templates(self):
  39. """
  40. Generate static files from templates
  41. """
  42. # render templates
  43. boot = self.boot()
  44. for wt in os.walk('templates'):
  45. for fname in wt[2]:
  46. if fname.split('.')[-1]=='html' and not fname.startswith('template'):
  47. fpath = os.path.relpath(os.path.join(wt[0], fname), 'templates')
  48. with open(os.path.join(wt[0], fname), 'r') as tempfile:
  49. temp = tempfile.read()
  50. temp = temp % boot
  51. with open(fpath, 'w') as outfile:
  52. outfile.write(temp)
  53. print "Rendered %s | %.2fkb" % (fpath, os.path.getsize(fpath) / 1024.0)
  54. def build(self):
  55. """
  56. build js files, index.html
  57. """
  58. for wt in os.walk('lib'):
  59. for fname in wt[2]:
  60. if fname=='build.json':
  61. self.bundle.make(os.path.join(wt[0], fname))
  62. self.render_templates()