henshin 0.4.2 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/LICENCE +18 -0
  2. data/README.md +133 -0
  3. data/Rakefile +6 -51
  4. data/bin/henshin +127 -134
  5. data/lib/henshin.rb +163 -38
  6. data/lib/henshin/compressor.rb +31 -0
  7. data/lib/henshin/compressors/css.rb +20 -0
  8. data/lib/henshin/compressors/js.rb +20 -0
  9. data/lib/henshin/core_ext.rb +69 -0
  10. data/lib/henshin/error.rb +28 -0
  11. data/lib/henshin/file.rb +67 -0
  12. data/lib/henshin/files/abstract.rb +102 -0
  13. data/lib/henshin/files/attributes.rb +31 -0
  14. data/lib/henshin/files/empty_template.rb +24 -0
  15. data/lib/henshin/files/physical.rb +117 -0
  16. data/lib/henshin/files/post.rb +64 -0
  17. data/lib/henshin/files/templatable.rb +29 -0
  18. data/lib/henshin/files/template.rb +45 -0
  19. data/lib/henshin/files/tilt.rb +50 -0
  20. data/lib/henshin/files/tilt_template.rb +45 -0
  21. data/lib/henshin/package.rb +27 -0
  22. data/lib/henshin/packages/script.rb +23 -0
  23. data/lib/henshin/packages/style.rb +20 -0
  24. data/lib/henshin/path.rb +143 -0
  25. data/lib/henshin/publisher.rb +42 -0
  26. data/lib/henshin/publishers/sftp.rb +79 -0
  27. data/lib/henshin/reader.rb +68 -0
  28. data/lib/henshin/safety.rb +74 -0
  29. data/lib/henshin/scope.rb +55 -0
  30. data/lib/henshin/site.rb +291 -228
  31. data/lib/henshin/ui.rb +35 -0
  32. data/lib/henshin/version.rb +3 -0
  33. data/lib/henshin/writer.rb +43 -0
  34. data/lib/rack/henshin.rb +113 -0
  35. data/site/assets/scripts/config.js +11 -0
  36. data/site/assets/styles/_mixins.sass +16 -0
  37. data/site/assets/styles/screen.sass +198 -0
  38. data/site/config.yml +13 -0
  39. data/site/drafts/a-work-in-progress.md +5 -0
  40. data/site/feed.xml.slim +19 -0
  41. data/site/index.html.slim +28 -0
  42. data/site/init.rb +33 -0
  43. data/site/posts/1-hello-world.md +46 -0
  44. data/site/posts/2-code-testing.md +36 -0
  45. data/site/posts/3-style-test.md +80 -0
  46. data/site/templates/default.slim +11 -0
  47. data/site/templates/post.slim +30 -0
  48. data/site/test.html.md +7 -0
  49. data/spec/helper.rb +70 -0
  50. data/spec/henshin/compressor_spec.rb +25 -0
  51. data/spec/henshin/compressors/css_spec.rb +22 -0
  52. data/spec/henshin/compressors/js_spec.rb +22 -0
  53. data/spec/henshin/core_ext_spec.rb +59 -0
  54. data/spec/henshin/error_spec.rb +22 -0
  55. data/spec/henshin/file_spec.rb +28 -0
  56. data/spec/henshin/files/abstract_spec.rb +98 -0
  57. data/spec/henshin/files/attributes_spec.rb +25 -0
  58. data/spec/henshin/files/empty_template_spec.rb +11 -0
  59. data/spec/henshin/files/physical_spec.rb +55 -0
  60. data/spec/henshin/files/post_spec.rb +66 -0
  61. data/spec/henshin/files/template_spec.rb +53 -0
  62. data/spec/henshin/files/tilt_spec.rb +59 -0
  63. data/spec/henshin/package_spec.rb +24 -0
  64. data/spec/henshin/packages/script_spec.rb +17 -0
  65. data/spec/henshin/packages/style_spec.rb +17 -0
  66. data/spec/henshin/path_spec.rb +56 -0
  67. data/spec/henshin/publisher_spec.rb +44 -0
  68. data/spec/henshin/publishers/sftp_spec.rb +21 -0
  69. data/spec/henshin/reader_spec.rb +55 -0
  70. data/spec/henshin/safety_spec.rb +66 -0
  71. data/spec/henshin/scope_spec.rb +33 -0
  72. data/spec/henshin/site_spec.rb +142 -0
  73. data/spec/henshin/ui_spec.rb +26 -0
  74. data/spec/henshin/writer_spec.rb +26 -0
  75. metadata +352 -197
  76. data/.gitignore +0 -27
  77. data/LICENSE +0 -20
  78. data/README.markdown +0 -35
  79. data/VERSION +0 -1
  80. data/henshin.gemspec +0 -121
  81. data/lib/henshin/archive.rb +0 -133
  82. data/lib/henshin/exec/files.rb +0 -46
  83. data/lib/henshin/ext.rb +0 -55
  84. data/lib/henshin/gen.rb +0 -154
  85. data/lib/henshin/labels.rb +0 -144
  86. data/lib/henshin/plugin.rb +0 -100
  87. data/lib/henshin/plugins/highlight.rb +0 -24
  88. data/lib/henshin/plugins/liquid.rb +0 -61
  89. data/lib/henshin/plugins/maruku.rb +0 -18
  90. data/lib/henshin/plugins/sass.rb +0 -24
  91. data/lib/henshin/plugins/textile.rb +0 -18
  92. data/lib/henshin/post.rb +0 -156
  93. data/lib/henshin/static.rb +0 -33
  94. data/test/helper.rb +0 -44
  95. data/test/site/css/_reset.sass +0 -34
  96. data/test/site/css/print.css +0 -12
  97. data/test/site/css/screen.sass +0 -70
  98. data/test/site/includes/head.html +0 -1
  99. data/test/site/index.html +0 -23
  100. data/test/site/layouts/archive_date.html +0 -20
  101. data/test/site/layouts/archive_month.html +0 -24
  102. data/test/site/layouts/archive_year.html +0 -26
  103. data/test/site/layouts/category_index.html +0 -27
  104. data/test/site/layouts/category_page.html +0 -20
  105. data/test/site/layouts/main.html +0 -13
  106. data/test/site/layouts/post.html +0 -36
  107. data/test/site/layouts/tag_index.html +0 -27
  108. data/test/site/layouts/tag_page.html +0 -20
  109. data/test/site/options.yaml +0 -17
  110. data/test/site/plugins/test.rb +0 -3
  111. data/test/site/posts/Testing-Stuff.markdown +0 -14
  112. data/test/site/posts/Textile-Test.textile +0 -7
  113. data/test/site/posts/cat/test.markdown +0 -6
  114. data/test/site/posts/lorem-ipsum.markdown +0 -7
  115. data/test/site/posts/same-date.markdown +0 -7
  116. data/test/site/static.html +0 -19
  117. data/test/suite.rb +0 -4
  118. data/test/test_gen.rb +0 -98
  119. data/test/test_options.rb +0 -73
  120. data/test/test_post.rb +0 -67
  121. data/test/test_site.rb +0 -197
  122. data/test/test_static.rb +0 -13
@@ -0,0 +1,35 @@
1
+ require 'clive/output'
2
+
3
+ module Henshin
4
+
5
+ module UI
6
+ extend self
7
+
8
+ LEFT_MARGIN = 14
9
+
10
+ def notify(msg, text)
11
+ return if Henshin.quiet?
12
+
13
+ s = ' ' * (LEFT_MARGIN - msg.clear_colours.size) + msg + ' ' + text.to_s
14
+ s.clear_colours! unless Henshin.colour?
15
+ puts s
16
+ end
17
+
18
+ def wrote(path, time=nil)
19
+ if time
20
+ notify (('%.3f' % time) + 's ').grey + 'wrote'.green.bold, path
21
+ else
22
+ notify 'wrote'.green.bold, path
23
+ end
24
+ end
25
+
26
+ def made(dir)
27
+ notify 'made'.grey, dir
28
+ end
29
+
30
+ def fail(msg)
31
+ abort msg.red
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Henshin
2
+ VERSION = "1.0.0.pre"
3
+ end
@@ -0,0 +1,43 @@
1
+ module Henshin
2
+
3
+ # Allows files to be written to the local file system.
4
+ class Writer
5
+
6
+ # @param root [Pathname] Path to where the Site is being written, individual
7
+ # file paths are calculated from this root.
8
+ def initialize(root)
9
+ @root = root
10
+ end
11
+
12
+ # Writes the +contents+ to the +path+ given.
13
+ #
14
+ # @param path [Pathname] Path of file to write
15
+ # @param contents [String] Contents of file to write
16
+ def write(path, contents)
17
+ return if Henshin.dry_run?
18
+
19
+ write_dir @root + path.dirname
20
+ write_file @root + path, contents
21
+ end
22
+
23
+ private
24
+
25
+ # Creates a directory at +dir+.
26
+ #
27
+ # @param dir [Pathname] Path of directory to create
28
+ def write_dir(dir)
29
+ FileUtils.mkdir_p(dir)
30
+ end
31
+
32
+ # Writes the file at +path+ with the +contents+ given.
33
+ #
34
+ # @param path [Pathname] Path to file to be written
35
+ # @param contents [String] Text to write to the file
36
+ def write_file(path, contents)
37
+ ::File.open path.to_s, 'w' do |file|
38
+ file.write contents
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,113 @@
1
+ require 'rack'
2
+ require 'rack/request'
3
+ require 'rack/response'
4
+
5
+ module Rack
6
+
7
+ class Henshin
8
+
9
+ def initialize(app, opts={})
10
+ @site = opts[:site]
11
+ end
12
+
13
+ def call(env)
14
+ time = Time.now if ::Henshin.profile?
15
+ a = @site.serve env['REQUEST_PATH']
16
+ puts "#{Time.now - time}s to serve #{env['REQUEST_PATH']}." if ::Henshin.profile?
17
+ a
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+
24
+ module Henshin
25
+
26
+ class Site
27
+ module Servable
28
+ def find_file(path)
29
+ all_files.find {|file| file.path === path } || MissingFile
30
+ end
31
+
32
+ # Finds the file which resolves the path given and serves it.
33
+ #
34
+ # @param path [String]
35
+ def serve(path)
36
+ find_file(path).serve
37
+ end
38
+ end
39
+ end
40
+
41
+ class File
42
+
43
+ # Extend a File instance with this module to allow it to be served using a
44
+ # rack interface.
45
+ module Servable
46
+
47
+ # @return [String] The mime type for the file to be written.
48
+ def mime
49
+ Rack::Mime.mime_type ::File.extname(permalink)
50
+ end
51
+
52
+ # @return [Array] The files content for serving through Rack.
53
+ def serve
54
+ [200, {"Content-Type" => mime}, [text]]
55
+ end
56
+ end
57
+
58
+ # A draft post. As drafts do not have a published date, this sets the date to
59
+ # be tomorrow.
60
+ module Draft
61
+ include Post
62
+
63
+ # @return [Date] Returns tomorrows date, since Drafts have no published date
64
+ # yet, but it is useful to have a date for previewing.
65
+ def date
66
+ Date.today + 1
67
+ end
68
+
69
+ # @return [false] Drafts have not been published.
70
+ def published?
71
+ false
72
+ end
73
+ end
74
+
75
+ apply %r{(^|/)drafts/}, Draft
76
+ end
77
+
78
+ # The sole missing file instance.
79
+ MissingFile = Object.new
80
+
81
+ # When served the missing file returns a 404 with appropriate message.
82
+ def MissingFile.serve
83
+ [404, {}, ["404 file not found"]]
84
+ end
85
+
86
+ # Site which adds all drafts to the list of posts.
87
+ class DraftSite < Site
88
+
89
+ # For the draft site speed is preferred over file size, so turn off any
90
+ # compression.
91
+ def defaults
92
+ super.deep_merge compress: {
93
+ scripts: false,
94
+ styles: false,
95
+ images: false
96
+ }
97
+ end
98
+
99
+ # @return [Array<Draft>] Returns all Draft posts read from the +drafts+
100
+ # folder.
101
+ def drafts
102
+ read(:all, 'drafts').sort
103
+ end
104
+
105
+ # @return [Array<Post, Draft>] Sorted array of Posts and Drafts, making
106
+ # previewing easier.
107
+ def posts
108
+ weave_posts (drafts + super).sort
109
+ end
110
+ end
111
+
112
+ use DraftSite
113
+ end
@@ -0,0 +1,11 @@
1
+ SyntaxHighlighter.config.tagName = "code";
2
+ SyntaxHighlighter.defaults['gutter'] = false;
3
+ SyntaxHighlighter.defaults['toolbar'] = false;
4
+
5
+ SyntaxHighlighter.autoloader(
6
+ 'ruby http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js',
7
+ 'js jscript javascript http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js',
8
+ 'applescript http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAppleScript.js'
9
+ );
10
+
11
+ SyntaxHighlighter.all();
@@ -0,0 +1,16 @@
1
+ @mixin border-radius($radius)
2
+ -webkit-border-radius: $radius
3
+ -moz-border-radius: $radius
4
+ -o-border-radius: $radius
5
+ border-radius: $radius
6
+
7
+ @mixin transition($time, $property)
8
+ -webkit-transition: $property $time
9
+ -moz-transition: $property $time
10
+ -ms-transition: $property $time
11
+ transition: $property $time
12
+
13
+ @mixin hyphenate
14
+ -webkit-hyphens: auto
15
+ -moz-hyphens: auto
16
+ hyphens: auto
@@ -0,0 +1,198 @@
1
+ @import mixins
2
+
3
+ $dark: #2d2d2d
4
+ $medium: #777
5
+ $light: #eee
6
+ $blinding: #fafafa
7
+
8
+ $line_height: 1.5em
9
+ $page_width: 37em
10
+
11
+ $body_font: Cambria, Georgia, serif
12
+ $header_font: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif
13
+ $code_font: Menlo, "Bitstream Vera Sans Mono", Consolas, "Lucida Console", monospace
14
+
15
+ html
16
+ background: $blinding
17
+ color: $dark
18
+ font:
19
+ family: $body_font
20
+ size: 16px
21
+ line-height: $line_height
22
+
23
+ body
24
+ max-width: $page_width
25
+ margin: 0 auto
26
+ padding: $line_height * 2
27
+
28
+ // FRONT --------------------------------------------------------------------
29
+
30
+ ul.list
31
+ list-style: circle
32
+ padding-left: 0
33
+
34
+
35
+ // HEADER -------------------------------------------------------------------
36
+
37
+ h1, h2, h3, h4, h5, h6
38
+ margin: $line_height 0 1em
39
+ font:
40
+ family: $header_font
41
+
42
+ header
43
+ margin: ($line_height * 4) 0 ($line_height * 3)
44
+
45
+ h1, h2
46
+ font:
47
+ weight: normal
48
+ style: italic
49
+ size: 2.7em
50
+ text-align: center
51
+
52
+ h2
53
+ font-size: 1.4em
54
+
55
+ // TOP ----------------------------------------------------------------------
56
+
57
+ nav
58
+ position: absolute
59
+ top: 0
60
+ height: 1.5em
61
+ padding: 0.5em 0
62
+ width: $page_width
63
+ border-bottom: 1px solid $light
64
+
65
+ a
66
+ margin: 0 1em
67
+ color: $medium
68
+ text-decoration: none
69
+
70
+ &:hover a
71
+ color: inherit
72
+
73
+ .prev
74
+ float: left
75
+
76
+ .next
77
+ float: right
78
+
79
+ .home
80
+ position: absolute
81
+ width: 50px
82
+ margin-left: -25px
83
+ left: 50%
84
+
85
+
86
+ // TEXT ---------------------------------------------------------------------
87
+
88
+ p
89
+ width: auto
90
+ margin: 0
91
+ text-indent: 0
92
+ text-align: justify
93
+ @include hyphenate
94
+
95
+ & + p
96
+ text-indent: $line_height
97
+
98
+ hr
99
+ margin: 0
100
+ height: $line_height * 2
101
+ border: none
102
+ position: relative
103
+
104
+ &:after
105
+ content: '~'
106
+ position: absolute
107
+ top: 0.27em
108
+ text-align: center
109
+ font-size: 2em
110
+ width: 100%
111
+ color: $light
112
+
113
+ blockquote
114
+ margin: $line_height 2em
115
+ font-style: italic
116
+ font-size: 1.1em
117
+ line-height: $line_height
118
+
119
+ a
120
+ color: $dark
121
+ text-decoration: underline
122
+ @include transition(color, .1s)
123
+
124
+ &:hover
125
+ text-decoration: none
126
+ color: rgb(50, 95, 150)
127
+
128
+ ul, ol
129
+ padding: 0 2em
130
+
131
+ .meta
132
+ margin-top: 3 * $line_height
133
+ border-top: 1px solid $light
134
+ color: $medium
135
+ text-align: right
136
+ padding: 0.5em 0
137
+
138
+ .metab
139
+ font:
140
+ size: 0.8em
141
+ family: Helvetica
142
+ margin-top: 3 * $line_height
143
+ background: $dark
144
+ color: $light
145
+ padding: .5em $line_height
146
+ text-shadow: 0 1px 0 rgba(0, 0, 0, .5)
147
+ @include border-radius(5px)
148
+
149
+ a
150
+ color: $blinding
151
+ text-decoration: none
152
+
153
+ .tags
154
+ float: right
155
+
156
+ // CODE ---------------------------------------------------------------------
157
+
158
+ pre
159
+ font-family: Menlo
160
+ font-size: 0.8em
161
+ line-height: 1.3em
162
+ padding: $line_height $line_height
163
+
164
+ pre code
165
+ font-size: 1em
166
+
167
+ code
168
+ font-family: Menlo
169
+ font-size: 0.9em
170
+
171
+ // Keywords and constants are bold
172
+ .k, .no, .keyword, .constant
173
+ font-weight: bold
174
+
175
+ // Fade punctuation slightly
176
+ .p
177
+ color: $medium
178
+
179
+ // Make comments italic and fade
180
+ .c1, .comment
181
+ font-style: italic
182
+ color: $medium
183
+
184
+ pre
185
+ div
186
+ .keyword, .constants
187
+ font-weight: bold
188
+
189
+ .comments
190
+ font-style: italic
191
+ color: $medium
192
+
193
+
194
+
195
+ // DRAFTS --------------------------------------------------------------------
196
+
197
+ li#draft
198
+ opacity: .7
@@ -0,0 +1,13 @@
1
+ title: Examplé Blog
2
+ author: You
3
+ url: http://example.com
4
+
5
+ description: >-
6
+ So I grew up in this place, with wires. Lots of wires. And then computers,
7
+ then suddenly we were all in this place. A soup. A soup of wires. They call
8
+ it the internet. I call it life.
9
+
10
+ projects:
11
+ - title: henshin
12
+ url: http://github.com/hawx/henshin
13
+ desc: The static site generator that created this site.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: A Work In Progress
3
+ ---
4
+
5
+ Hey look this is clearly a draft post...