octopress-ink 1.0.0.alpha.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +38 -0
  6. data/Rakefile +1 -0
  7. data/lib/octopress-ink.rb +37 -0
  8. data/lib/octopress-ink/assets.rb +10 -0
  9. data/lib/octopress-ink/assets/asset.rb +71 -0
  10. data/lib/octopress-ink/assets/javascript.rb +9 -0
  11. data/lib/octopress-ink/assets/layout.rb +25 -0
  12. data/lib/octopress-ink/assets/sass.rb +64 -0
  13. data/lib/octopress-ink/assets/static_file.rb +26 -0
  14. data/lib/octopress-ink/assets/static_file_content.rb +13 -0
  15. data/lib/octopress-ink/assets/stylesheet.rb +24 -0
  16. data/lib/octopress-ink/assets/template.rb +20 -0
  17. data/lib/octopress-ink/generators/plugin_assets.rb +9 -0
  18. data/lib/octopress-ink/helpers/content_for.rb +29 -0
  19. data/lib/octopress-ink/jekyll/hooks.rb +12 -0
  20. data/lib/octopress-ink/plugin.rb +142 -0
  21. data/lib/octopress-ink/plugins.rb +232 -0
  22. data/lib/octopress-ink/plugins/sass.rb +18 -0
  23. data/lib/octopress-ink/tags.rb +14 -0
  24. data/lib/octopress-ink/tags/content_for.rb +17 -0
  25. data/lib/octopress-ink/tags/embed.rb +28 -0
  26. data/lib/octopress-ink/tags/footer.rb +10 -0
  27. data/lib/octopress-ink/tags/head.rb +10 -0
  28. data/lib/octopress-ink/tags/javascript.rb +18 -0
  29. data/lib/octopress-ink/tags/scripts.rb +10 -0
  30. data/lib/octopress-ink/tags/stylesheet.rb +18 -0
  31. data/lib/octopress-ink/tags/wrap_yield.rb +25 -0
  32. data/lib/octopress-ink/tags/yield.rb +16 -0
  33. data/lib/octopress-ink/version.rb +5 -0
  34. data/octopress-ink.gemspec +27 -0
  35. data/test/.gitignore +1 -0
  36. data/test/Gemfile +8 -0
  37. data/test/_config.yml +14 -0
  38. data/test/_custom/theme/layouts/default.html +17 -0
  39. data/test/_custom/theme/stylesheets/_bazz.scss +1 -0
  40. data/test/_custom/theme/stylesheets/bar.scss +4 -0
  41. data/test/_custom/theme/stylesheets/site.css +1 -0
  42. data/test/_plugins/bundler.rb +23 -0
  43. data/test/_plugins/theme/embeds/foo.html +1 -0
  44. data/test/_plugins/theme/files/test.html +1 -0
  45. data/test/_plugins/theme/javascripts/bar.js +1 -0
  46. data/test/_plugins/theme/javascripts/foo.js +1 -0
  47. data/test/_plugins/theme/layouts/default.html +18 -0
  48. data/test/_plugins/theme/layouts/test.html +4 -0
  49. data/test/_plugins/theme/stylesheets/_baz.scss +1 -0
  50. data/test/_plugins/theme/stylesheets/bar.scss +4 -0
  51. data/test/_plugins/theme/stylesheets/foo.css +1 -0
  52. data/test/_plugins/theme/stylesheets/print.css +1 -0
  53. data/test/_plugins/theme/stylesheets/site.css +3 -0
  54. data/test/index.md +13 -0
  55. data/test/stylesheets/_foo.scss +1 -0
  56. data/test/stylesheets/site.sass +7 -0
  57. metadata +177 -0
@@ -0,0 +1,12 @@
1
+
2
+ module Jekyll
3
+ module Convertible
4
+ alias_method :do_layout_orig, :do_layout
5
+
6
+ def do_layout(payload, layouts)
7
+ # The contentblock tags needs access to the converter to process it while rendering.
8
+ payload['converter'] = self.converter
9
+ do_layout_orig(payload, layouts)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,142 @@
1
+ module Octopress
2
+ class Plugin
3
+ attr_accessor :name, :type, :asset_override, :assets_path,
4
+ :layouts_dir, :stylesheets_dir, :javascripts_dir, :files_dir, :embeds_dir, :images_dir,
5
+ :layouts, :embeds, :stylesheets, :javascripts, :images, :sass, :fonts, :files
6
+
7
+ def initialize(name, type)
8
+ @layouts_dir = 'layouts'
9
+ @files_dir = 'files'
10
+ @fonts_dir = 'fonts'
11
+ @images_dir = 'images'
12
+ @embeds_dir = 'embeds'
13
+ @javascripts_dir = 'javascripts'
14
+ @stylesheets_dir = 'stylesheets'
15
+ @name = name
16
+ @type = type
17
+ @layouts = []
18
+ @embeds = []
19
+ @stylesheets = []
20
+ @javascripts = []
21
+ @images = []
22
+ @sass = []
23
+ @fonts = []
24
+ @files = []
25
+ add_assets
26
+ add_layouts
27
+ add_embeds
28
+ end
29
+
30
+ def add_assets
31
+
32
+ end
33
+
34
+ def namespace
35
+ if @type == 'local_plugin'
36
+ ''
37
+ else
38
+ @type == 'theme' ? @type : @name
39
+ end
40
+ end
41
+
42
+ def add_stylesheet(file, media=nil)
43
+ @stylesheets << Assets::Stylesheet.new(self, @stylesheets_dir, file, media)
44
+ end
45
+
46
+ def add_sass(file, media=nil)
47
+ begin
48
+ require 'sass'
49
+ rescue LoadError
50
+ raise IOError.new "The #{@name} #{@type} uses the Sass gem. You'll need to add it to your Gemfile or run `gem install sass`"
51
+ end
52
+ @sass << Assets::Sass.new(self, @stylesheets_dir, file, media)
53
+ end
54
+
55
+ def add_javascript(file)
56
+ @javascripts << Assets::Javascript.new(self, @javascripts_dir, file)
57
+ end
58
+
59
+ def add_layouts
60
+ if @assets_path
61
+ base = File.join(@assets_path, @layouts_dir)
62
+ entries = []
63
+ Dir.chdir(base) { entries = Dir['**/*.*'] }
64
+ entries.each do |file|
65
+ @layouts << Assets::Layout.new(self, @layouts_dir, file)
66
+ end
67
+ end
68
+ end
69
+
70
+ def add_embeds
71
+ @embeds = Assets::Template.new(self, @embeds_dir)
72
+ end
73
+
74
+ def add_image(file)
75
+ @images << Assets::Asset.new(self, @images_dir, file)
76
+ end
77
+
78
+ def add_font(file)
79
+ @fonts << Assets::Asset.new(self, @fonts_dir, file)
80
+ end
81
+
82
+ def add_file(file)
83
+ @files << Assets::Asset.new(self, @files_dir, file)
84
+ end
85
+
86
+ def add_stylesheets(files, media=nil)
87
+ files.each { |f| add_stylesheet(f, media) }
88
+ end
89
+
90
+ def add_sass_files(files, media=nil)
91
+ files.each { |f| add_sass(f, media) }
92
+ end
93
+
94
+ def add_javascripts(files)
95
+ files.each { |f| add_javascript(f) }
96
+ end
97
+
98
+ def add_images(files)
99
+ files.each { |f| add_image(f) }
100
+ end
101
+
102
+ def add_fonts(files)
103
+ files.each { |f| add_font(f) }
104
+ end
105
+
106
+ def add_files(files)
107
+ files.each { |f| add_file(f) }
108
+ end
109
+
110
+ def stylesheet_paths(site)
111
+ get_paths(@stylesheets, site)
112
+ end
113
+
114
+ def javascript_paths(site)
115
+ get_paths(@javascripts, site)
116
+ end
117
+
118
+ def stylesheet_tags
119
+ get_tags(@stylesheets)
120
+ end
121
+
122
+ def sass_tags
123
+ get_tags(@sass)
124
+ end
125
+
126
+ def javascript_tags
127
+ get_tags(@javascripts)
128
+ end
129
+
130
+ def get_paths(files, site)
131
+ files.dup.map { |f| f.path(site) }
132
+ end
133
+
134
+ def get_tags(files)
135
+ files.dup.map { |f| f.tag }
136
+ end
137
+
138
+ def embed(file, site)
139
+ @embeds.file(file, site)
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,232 @@
1
+ module Octopress
2
+ module Plugins
3
+ @plugins = []
4
+ @local_plugins = []
5
+
6
+ def self.theme
7
+ @theme
8
+ end
9
+
10
+ def self.plugin(name)
11
+ if name == 'theme'
12
+ @theme
13
+ else
14
+ @plugins.concat(@local_plugins).each do |p|
15
+ return p if p.name == name
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.plugins
21
+ [@theme].concat(@plugins).concat(@local_plugins).compact
22
+ end
23
+
24
+ def self.embed(name, file, site)
25
+ plugin(name).embed(file, site)
26
+ end
27
+
28
+ def self.register_plugin(plugin, name, type='plugin')
29
+ new_plugin = plugin.new(name, type)
30
+
31
+ if type == 'theme'
32
+ @theme = new_plugin
33
+ elsif type == 'local_plugin'
34
+ @plugins << new_plugin
35
+ else
36
+ @local_plugins << new_plugin
37
+ end
38
+ end
39
+
40
+ def self.register_layouts(site)
41
+ plugins.each do |p|
42
+ p.layouts.clone.each { |layout| layout.register(site) }
43
+ end
44
+ end
45
+
46
+ def self.custom_dir(site)
47
+ site.config['custom'] || CUSTOM_DIR
48
+ end
49
+
50
+ def self.fingerprint(paths)
51
+ paths = [paths] unless paths.is_a? Array
52
+ Digest::MD5.hexdigest(paths.clone.map! { |path| "#{File.mtime(path).to_i}" }.join)
53
+ end
54
+
55
+ def self.combined_stylesheet_path(media)
56
+ File.join('stylesheets', "site-#{media}-#{@combined_stylesheets[media][:fingerprint]}.css")
57
+ end
58
+
59
+ def self.combined_javascript_path
60
+ print = @javascript_fingerprint || ''
61
+ File.join('javascripts', "site-#{print}.js")
62
+ end
63
+
64
+ def self.write_files(site, source, dest)
65
+ site.static_files << StaticFileContent.new(source, dest)
66
+ end
67
+
68
+ def self.compile_sass_file(path, options)
69
+ ::Sass.compile_file(path, options)
70
+ end
71
+
72
+ def self.compile_sass(contents, options)
73
+ ::Sass.compile(contents, options)
74
+ end
75
+
76
+ def self.sass_config(site, item, default)
77
+ if site.config['sass'] && site.config['sass'][item]
78
+ site.config['sass'][item]
79
+ else
80
+ default
81
+ end
82
+ end
83
+
84
+ def self.sass_options(site)
85
+ options = {
86
+ style: sass_config(site, 'output_style', 'compressed').to_sym,
87
+ trace: sass_config(site, 'trace', false),
88
+ line_numbers: sass_config(site, 'line_numbers', false)
89
+ }
90
+ end
91
+
92
+ def self.write_combined_stylesheet(site)
93
+ css = combine_stylesheets(site)
94
+ css.keys.each do |media|
95
+ options = sass_options(site)
96
+ options[:line_numbers] = false
97
+ contents = compile_sass(css[media][:contents], options)
98
+ write_files(site, contents, combined_stylesheet_path(media))
99
+ end
100
+ end
101
+
102
+ def self.write_combined_javascript(site)
103
+ write_files(site, combine_javascripts(site), combined_javascript_path)
104
+ end
105
+
106
+ def self.combine_stylesheets(site)
107
+ unless @combined_stylesheets
108
+ css = {}
109
+ paths = {}
110
+ plugins.each do |plugin|
111
+ plugin_header = "/* #{name} #{plugin.type} */\n"
112
+ stylesheets = plugin.stylesheets.clone.concat plugin.sass
113
+ stylesheets.each do |file|
114
+ css[file.media] ||= {}
115
+ css[file.media][:contents] ||= ''
116
+ css[file.media][:contents] << plugin_header
117
+ css[file.media][:paths] ||= []
118
+
119
+ # Add Sass files
120
+ if file.respond_to? :compile
121
+ css[file.media][:contents].concat file.compile(site)
122
+ else
123
+ css[file.media][:contents].concat file.path(site).read.strip
124
+ end
125
+ css[file.media][:paths] << file.path(site)
126
+ plugin_header = ''
127
+ end
128
+ end
129
+
130
+ css.keys.each do |media|
131
+ css[media][:fingerprint] = fingerprint(css[media][:paths])
132
+ end
133
+ @combined_stylesheets = css
134
+ end
135
+ @combined_stylesheets
136
+ end
137
+
138
+ def self.combine_javascripts(site)
139
+ js = ''
140
+ plugins.each do |plugin|
141
+ paths = plugin.javascript_paths(site)
142
+ @javascript_fingerprint = fingerprint(paths)
143
+ paths.each do |file|
144
+ js.concat Pathname.new(file).read
145
+ end
146
+ end
147
+ js
148
+ end
149
+
150
+ def self.combined_stylesheet_tag(site)
151
+ tags = ''
152
+ combine_stylesheets(site).keys.each do |media|
153
+ tags.concat "<link href='/#{combined_stylesheet_path(media)}' media='#{media}' rel='stylesheet' type='text/css'>"
154
+ end
155
+ tags
156
+ end
157
+
158
+ def self.combined_javascript_tag
159
+ "<script src='/#{combined_javascript_path}'></script>"
160
+ end
161
+
162
+ def self.stylesheet_tags
163
+ css = []
164
+ plugins.each do |plugin|
165
+ css.concat plugin.stylesheet_tags
166
+ css.concat plugin.sass_tags
167
+ end
168
+ css
169
+ end
170
+
171
+ def self.javascript_tags
172
+ js = []
173
+ plugins.each do |plugin|
174
+ js.concat plugin.javascript_tags
175
+ end
176
+ js
177
+ end
178
+
179
+ def self.copy_javascripts(site)
180
+ plugins.each do |plugin|
181
+ copy(plugin.javascripts, site)
182
+ end
183
+ end
184
+
185
+ def self.copy_stylesheets(site)
186
+ plugins.each do |plugin|
187
+ stylesheets = plugin.stylesheets.clone.concat plugin.sass
188
+ copy(stylesheets, site)
189
+ end
190
+ end
191
+
192
+ def self.add_static_files(site)
193
+
194
+ if site.config['sass'] and site.config['sass']['files']
195
+ plugin('sass').add_files site.config['sass']['files']
196
+ end
197
+
198
+ # Copy/Generate Stylesheets
199
+ #
200
+ if site.config['octopress'] && site.config['octopress']['combine_stylesheets'] != false
201
+ copy_stylesheets(site)
202
+ else
203
+ write_combined_stylesheet(site)
204
+ end
205
+
206
+ # Copy/Generate Javascripts
207
+ #
208
+ if site.config['octopress'] && site.config['octopress']['combine_javascripts'] != false
209
+ copy_javascripts(site)
210
+ else
211
+ write_combined_javascript(site)
212
+ end
213
+
214
+ # Copy other assets
215
+ #
216
+ copy_static_files(site)
217
+ end
218
+
219
+ def self.copy_static_files(site)
220
+ plugins.each do |plugin|
221
+ copy(plugin.files, site)
222
+ copy(plugin.images, site)
223
+ copy(plugin.fonts, site)
224
+ end
225
+ end
226
+
227
+ def self.copy(files, site)
228
+ files.each { |f| f.copy(site) }
229
+ end
230
+ end
231
+ end
232
+
@@ -0,0 +1,18 @@
1
+ # The sass assets for this plugin are populated at runtime by the add_static_files method of
2
+ # the Plugins module.
3
+ #
4
+ module Octopress
5
+ class SassPlugin < Octopress::Plugin
6
+ def add_files(files)
7
+ files = [files] unless files.is_a? Array
8
+ files.each do |file|
9
+ if file.is_a? Array
10
+ add_sass file.first, file.last
11
+ else
12
+ add_sass file
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,14 @@
1
+ module Octopress
2
+ module Tags
3
+ autoload :EmbedTag, 'octopress-ink/tags/embed'
4
+ autoload :JavascriptTag, 'octopress-ink/tags/javascript'
5
+ autoload :StylesheetTag, 'octopress-ink/tags/stylesheet'
6
+ autoload :ContentForBlock, 'octopress-ink/tags/content_for'
7
+ autoload :HeadBlock, 'octopress-ink/tags/head'
8
+ autoload :FooterBlock, 'octopress-ink/tags/footer'
9
+ autoload :YieldTag, 'octopress-ink/tags/yield'
10
+ autoload :ScriptsBlock, 'octopress-ink/tags/scripts'
11
+ autoload :WrapYieldBlock, 'octopress-ink/tags/wrap_yield'
12
+ end
13
+ end
14
+
@@ -0,0 +1,17 @@
1
+ # Inspired by jekyll-contentblocks https://github.com/rustygeldmacher/jekyll-contentblocks
2
+ module Octopress
3
+ module Tags
4
+ class ContentForBlock < Liquid::Block
5
+
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @block_name ||= Helpers::ContentFor.get_block_name(tag_name, markup)
9
+ end
10
+
11
+ def render(context)
12
+ Helpers::ContentFor.append_to_block(context, @block_name, super.strip)
13
+ ''
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ module Octopress
2
+ module Tags
3
+ class EmbedTag < Liquid::Tag
4
+ EMBED_SYNTAX = /(.+?)\/(\S+)/
5
+
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @markup = markup
9
+ if @markup.strip =~ EMBED_SYNTAX
10
+ @plugin = $1
11
+ @path = $2
12
+ else
13
+ raise IOError.new "Invalid Syntax: for embed tag. {% embed #{@markup.strip} %} should be {% embed plugin/file %}"
14
+ end
15
+ end
16
+
17
+ def render(context)
18
+ content = Plugins.embed(@plugin, @path, context.registers[:site]).read
19
+ partial = Liquid::Template.parse(content)
20
+ context.stack {
21
+ context['embed'] = Jekyll::Tags::IncludeTag.new('include', @markup, []).parse_params(context)
22
+ partial.render!(context)
23
+ }.strip
24
+ end
25
+ end
26
+ end
27
+ end
28
+