octopress-ink 1.0.0.alpha.44 → 1.0.0.alpha.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -6
  3. data/assets/docs/_plugin-template.markdown +9 -21
  4. data/assets/docs/creating-a-plugin.markdown +90 -12
  5. data/lib/octopress-ink/assets/asset.rb +55 -26
  6. data/lib/octopress-ink/assets/coffeescript.rb +22 -0
  7. data/lib/octopress-ink/assets/config.rb +12 -8
  8. data/lib/octopress-ink/assets/doc_page.rb +21 -18
  9. data/lib/octopress-ink/assets/file.rb +9 -7
  10. data/lib/octopress-ink/assets/javascript.rb +7 -0
  11. data/lib/octopress-ink/assets/layout.rb +3 -1
  12. data/lib/octopress-ink/assets/page.rb +12 -10
  13. data/lib/octopress-ink/assets/sass.rb +24 -17
  14. data/lib/octopress-ink/assets/stylesheet.rb +12 -6
  15. data/lib/octopress-ink/assets.rb +1 -4
  16. data/lib/octopress-ink/commands/helpers.rb +7 -4
  17. data/lib/octopress-ink/commands/init.rb +48 -0
  18. data/lib/octopress-ink/commands/list.rb +1 -1
  19. data/lib/octopress-ink/commands/new.rb +126 -49
  20. data/lib/octopress-ink/commands.rb +2 -0
  21. data/lib/octopress-ink/configuration.rb +18 -10
  22. data/lib/octopress-ink/filters.rb +4 -4
  23. data/lib/octopress-ink/generators/plugin_assets.rb +3 -2
  24. data/lib/octopress-ink/helpers/path.rb +4 -4
  25. data/lib/octopress-ink/jekyll/hooks.rb +123 -7
  26. data/lib/octopress-ink/jekyll/page.rb +3 -1
  27. data/lib/octopress-ink/plugin.rb +198 -165
  28. data/lib/octopress-ink/plugin_asset_pipeline.rb +172 -0
  29. data/lib/octopress-ink/plugins.rb +44 -168
  30. data/lib/octopress-ink/tags/javascript.rb +1 -1
  31. data/lib/octopress-ink/tags/render.rb +4 -2
  32. data/lib/octopress-ink/tags/stylesheet.rb +1 -1
  33. data/lib/octopress-ink/utils.rb +42 -0
  34. data/lib/octopress-ink/version.rb +1 -1
  35. data/lib/octopress-ink.rb +70 -34
  36. data/octopress-ink.gemspec +2 -2
  37. data/test/_combine_false.yml +4 -0
  38. data/test/_config.yml +1 -1
  39. data/test/combine_css/stylesheets/all-e10f647557c9d610df6df40a458bc823.css +15 -0
  40. data/test/{sass_expanded → combine_css}/stylesheets/print-0dc274efb4e3fba0ae71bd22eef6fb38.css +2 -4
  41. data/test/{concat_css_false → combine_css_false}/stylesheets/awesome-sauce/plugin-media-test.css +0 -0
  42. data/test/{concat_css_false → combine_css_false}/stylesheets/awesome-sauce/plugin-test.css +0 -0
  43. data/test/{concat_css_false → combine_css_false}/stylesheets/site.css +0 -0
  44. data/test/{concat_css_false → combine_css_false}/stylesheets/test.css +0 -0
  45. data/test/{concat_css_false → combine_css_false}/stylesheets/theme/theme-media-test.css +0 -0
  46. data/test/{concat_css_false → combine_css_false}/stylesheets/theme/theme-test.css +0 -0
  47. data/test/{concat_css_false → combine_css_false}/stylesheets/theme/theme-test2.css +0 -0
  48. data/test/combine_js/javascripts/all-d41d8cd98f00b204e9800998ecf8427e.js +7 -0
  49. data/test/{concat_js_false → combine_js_false}/javascripts/site.js +0 -0
  50. data/test/combine_js_false/javascripts/test.js +10 -0
  51. data/test/{concat_js_false → combine_js_false}/javascripts/theme/bar.js +0 -0
  52. data/test/{concat_js_false → combine_js_false}/javascripts/theme/foo.js +0 -0
  53. data/test/copy_layouts_pages/_copy/pages/two.md +0 -1
  54. data/test/copy_test/_copy/pages/two.md +0 -1
  55. data/test/copy_test/_copy/stylesheets/main.scss +4 -1
  56. data/test/expected/index.html +2 -2
  57. data/test/plugins/awesome-sauce/pages/b.html +0 -1
  58. data/test/plugins/awesome-sauce/plugin.rb +1 -1
  59. data/test/plugins/test-theme/javascripts/blah.coffee +1 -0
  60. data/test/plugins/test-theme/plugin.rb +1 -1
  61. data/test/plugins/test-theme/stylesheets/main.scss +4 -1
  62. data/test/source/_plugins/awesome-sauce/config.yml +1 -1
  63. data/test/source/_plugins/theme/config.yml +1 -1
  64. data/test/source/_posts/2014-02-01-test-post.md +1 -0
  65. data/test/source/index.md +2 -2
  66. data/test/test.rb +15 -27
  67. metadata +66 -84
  68. data/lib/octopress-ink/assets/local_asset.rb +0 -47
  69. data/lib/octopress-ink/assets/local_javascript.rb +0 -12
  70. data/lib/octopress-ink/assets/local_sass.rb +0 -30
  71. data/lib/octopress-ink/assets/local_stylesheet.rb +0 -33
  72. data/lib/octopress-ink/helpers/titlecase.rb +0 -37
  73. data/lib/octopress-ink/plugins/asset_pipeline.rb +0 -103
  74. data/test/_concat_false.yml +0 -2
  75. data/test/_sass_compact.yml +0 -4
  76. data/test/_sass_expanded.yml +0 -4
  77. data/test/concat_css/stylesheets/all-e10f647557c9d610df6df40a458bc823.css +0 -1
  78. data/test/concat_css/stylesheets/print-0dc274efb4e3fba0ae71bd22eef6fb38.css +0 -1
  79. data/test/concat_js/javascripts/all-d41d8cd98f00b204e9800998ecf8427e.js +0 -3
  80. data/test/sass_compact/stylesheets/all-e10f647557c9d610df6df40a458bc823.css +0 -18
  81. data/test/sass_compact/stylesheets/print-0dc274efb4e3fba0ae71bd22eef6fb38.css +0 -5
  82. data/test/sass_expanded/stylesheets/all-e10f647557c9d610df6df40a458bc823.css +0 -36
  83. data/test/source/_javascripts/site.js +0 -1
  84. data/test/source/_stylesheets/_foo.scss +0 -1
  85. data/test/source/_stylesheets/site.sass +0 -7
  86. data/test/source/_stylesheets/test.css +0 -1
@@ -6,13 +6,16 @@ module Octopress
6
6
  c.option "layouts", "--layouts", "#{action} only layouts"
7
7
  c.option "includes", "--includes", "#{action} only includes"
8
8
  c.option "pages", "--pages", "#{action} only pages"
9
- c.option "stylesheets", "--stylesheets", "#{action} only Stylesheets (CSS and Sass)"
10
- c.option "css", "--css", "#{action} only CSS files"
11
- c.option "sass", "--sass", "#{action} only Sass files"
12
- c.option "javascripts", "--javascripts", "#{action} only Javascripts"
9
+ c.option "stylesheets", "--stylesheets", "#{action} only Stylesheets (.css, .scss, .sass)"
10
+ c.option "css", "--css", "#{action} only CSS files (.css)"
11
+ c.option "sass", "--sass", "#{action} only Sass files (.scss, .sass)"
12
+ c.option "javascripts", "--javascripts", "#{action} only Javascripts (.js and .coffee)"
13
+ c.option "js", "--js", "#{action} only Javascript files (.js)"
14
+ c.option "coffee", "--coffee", "#{action} only Coffeescript files (.coffee)"
13
15
  c.option "images", "--images", "#{action} only images"
14
16
  c.option "fonts", "--fonts", "#{action} only fonts"
15
17
  c.option "files", "--files", "#{action} only files"
18
+ c.option "defaults", "--defaults", "#{action} plugin's default configuration"
16
19
  c.option "config", "--config <CONFIG_FILE>[,CONFIG_FILE2,...]", Array, "Custom configuration file"
17
20
  end
18
21
  end
@@ -0,0 +1,48 @@
1
+ module Octopress
2
+ module Ink
3
+ module Commands
4
+ class Init
5
+ def self.process_command(p)
6
+ p.command(:init) do |c|
7
+ c.syntax "init <PATH> [options]"
8
+ c.description "Add Octopress Ink scaffolding to an existing gem based plugin."
9
+ c.option "theme", "--theme", "Plugin will be a theme."
10
+
11
+ c.action do |args, options|
12
+ if args.empty?
13
+ raise "Please provide a plugin name, e.g. my_awesome_plugin."
14
+ else
15
+ @options = options
16
+ @options['path'] = args[0]
17
+ init_plugin
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.init_plugin
24
+ settings = New.gem_settings(@options['path'])
25
+ settings[:type] = @options['theme'] ? 'theme' : 'plugin'
26
+
27
+ New.add_asset_dirs(settings)
28
+ New.add_demo_files(settings)
29
+
30
+ puts "\nTo finish setting up your Octopress Ink plugin:\n".bold
31
+ puts "1. Add gem requirements to your gemspec:\n\n"
32
+ puts New.dependencies(settings).sub("\n\n", "\n").yellow
33
+ puts "2. Add an Octopress Ink plugin to your gem, making changes as necessary:\n\n"
34
+
35
+ template = <<-HERE
36
+ require "octopress-ink"
37
+
38
+ Octopress::Ink.add_plugin({
39
+ #{New.indent(New.plugin_config(settings))}
40
+ })
41
+ HERE
42
+
43
+ puts template.yellow
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -15,7 +15,7 @@ module Octopress
15
15
  Octopress::Ink.list(options)
16
16
  else
17
17
  name = args.first
18
- Octopress::Ink.plugin_info(name, options)
18
+ Octopress::Ink.plugin_list(name, options)
19
19
  end
20
20
  end
21
21
  end
@@ -6,15 +6,15 @@ module Octopress
6
6
  p.command(:new) do |c|
7
7
  c.syntax "new <PLUGIN_NAME> [options]"
8
8
  c.description "Create a new Octopress Ink plugin with Ruby gem scaffolding."
9
- c.option "path", "--path PATH", "Create a plugin at a specified path (defaults to current directory)."
10
9
  c.option "theme", "--theme", "Create a new theme."
10
+ c.option "path", "--path PATH", "Create a plugin at a specified path (defaults to current directory)."
11
11
 
12
12
  c.action do |args, options|
13
13
  if args.empty?
14
14
  raise "Please provide a plugin name, e.g. my_awesome_plugin."
15
15
  else
16
- options['name'] = args[0]
17
16
  @options = options
17
+ @options['name'] = args[0]
18
18
  new_plugin
19
19
  end
20
20
  end
@@ -24,28 +24,32 @@ module Octopress
24
24
  def self.new_plugin
25
25
  path = @options['path'] ||= Dir.pwd
26
26
  gem_name = @options['name']
27
-
28
- @gem_dir = File.join(path, gem_name)
29
- @gemspec_file = "#{gem_name}/#{gem_name}.gemspec"
27
+ path_to_gem = File.join(path, gem_name)
30
28
 
31
29
  if !Dir.exist?(path)
32
30
  raise "Directory not found: #{File.expand_path(path)}."
33
31
  end
34
32
 
35
- if !Dir["#{@gem_dir}/*"].empty?
36
- raise "Directory not empty: #{File.expand_path(@gem_dir)}."
33
+ if !Dir["#{path_to_gem}/*"].empty?
34
+ raise "Directory not empty: #{File.expand_path(path_to_gem)}."
37
35
  end
38
36
 
39
37
  FileUtils.cd path do
40
- create_gem
38
+ create_gem(gem_name)
39
+
40
+ @settings = gem_settings(path_to_gem)
41
+ @settings[:type] = @options['theme'] ? 'theme' : 'plugin'
42
+
41
43
  add_dependency
42
44
  add_plugin
43
- add_asset_dirs
45
+ add_assets
44
46
  add_demo_files
45
47
  end
46
48
  end
47
49
 
48
- def self.create_gem
50
+ # Create a new gem with Bundle's gem command
51
+ #
52
+ def self.create_gem(name)
49
53
  begin
50
54
  require 'bundler/cli'
51
55
  bundler = Bundler::CLI.new
@@ -53,21 +57,27 @@ module Octopress
53
57
  raise "To use this feautre you'll need to install the bundler gem with `gem install bundler`."
54
58
  end
55
59
 
56
- bundler.gem(@options['name'])
60
+ bundler.gem(name)
57
61
  end
58
62
 
59
63
  # Add Octopress Ink dependency to Gemspec
60
64
  #
61
65
  def self.add_dependency
62
- minor_version = VERSION.scan(/\d\.\d/)[0]
63
- @gemspec = File.open(@gemspec_file).read
64
- dependency = " spec.add_runtime_dependency 'octopress-ink', '~> #{minor_version}', '>= #{VERSION}'\n"
65
- dependency += "\n spec.add_development_dependency 'octopress'\n"
66
+ pos = @settings[:gemspec].rindex("end")
67
+ @settings[:gemspec] = insert_before(@settings[:gemspec], pos, indent(dependencies))
66
68
 
67
- pos = @gemspec.index(" spec.add_development_dependency")
68
- @gemspec = insert_before(@gemspec, pos, dependency)
69
+ File.open(@settings[:gemspec_path], 'w+') {|f| f.write(@settings[:gemspec]) }
70
+ end
69
71
 
70
- File.open(@gemspec_file, 'w+') {|f| f.write(@gemspec) }
72
+ # Returns lines which need to be added as a dependency
73
+ #
74
+ # spec_var - variable used to assign gemspec attributes,
75
+ # e.g. "spec" as in spec.name = "gem name"
76
+ #
77
+ def self.dependencies
78
+ minor_version = VERSION.scan(/\d\.\d/)[0]
79
+ d = "#{@settings[:spec_var]}.add_development_dependency \"octopress\"\n\n"
80
+ d += "#{@settings[:spec_var]}.add_runtime_dependency \"octopress-ink\", \"~> #{minor_version}\", \">= #{VERSION}\"\n"
71
81
  end
72
82
 
73
83
  # Add Octopress Ink plugin to core module file
@@ -75,78 +85,145 @@ module Octopress
75
85
  def self.add_plugin
76
86
  # Grab the module directory from the version.rb require.
77
87
  # If a gem is created with dashes e.g. "some-gem", Bundler puts the module file at lib/some/gem.rb
78
- module_subpath = @gemspec.scan(/['"](.+)\/version['"]/).flatten[0]
79
- @module_file = File.join(@options['name'], 'lib', "#{module_subpath}.rb")
80
- mod = File.open(@module_file).read
81
-
82
- # Find the inner most module name
83
- @modules = mod.scan(/module\s+(.+?)\n/).flatten
84
- @mod_path = @modules.join('::')
85
-
88
+ file = File.join(@settings[:path], @settings[:module_path])
89
+ mod = File.open(file).read
86
90
  mod = add_simple_plugin mod
87
91
 
88
- File.open(@module_file, 'w+') {|f| f.write(mod) }
92
+ File.open(file, 'w+') {|f| f.write(mod) }
89
93
  end
90
94
 
91
- def self.add_asset_dirs
92
- %w{images fonts pages files layouts includes stylesheets javascripts}.each do |asset|
93
- dir = File.join(@options['name'], 'assets', asset)
94
- FileUtils.mkdir_p dir
95
+ def self.add_assets
96
+ dirs = %w{docs images fonts pages files layouts includes stylesheets javascripts}.map do |asset|
97
+ File.join(@settings[:path], 'assets', asset)
95
98
  end
99
+ create_empty_dirs dirs
100
+
101
+ # Add empty configuration file
102
+ FileUtils.touch File.join(@settings[:path], 'assets', 'config.yml')
96
103
  end
97
104
 
98
105
  # New plugin uses a simple configuration hash
99
106
  #
100
107
  def self.add_simple_plugin(mod)
101
- mod = mod.scan(/require.+\n/)[0]
102
- mod += 'require "octopress-ink"'
103
- mod += "\n\nOctopress::Ink.new_plugin({\n#{indent(plugin_config)}\n})"
108
+ mod = "#{@settings[:require_version]}\n"
109
+ mod += "require 'octopress-ink'\n"
110
+ mod += "\nOctopress::Ink.add_plugin({\n#{indent(plugin_config)}\n})"
104
111
  end
105
112
 
113
+
114
+ # Return an Ink Plugin configuration hash desinged for this gem
115
+ #
106
116
  def self.plugin_config
107
- plugin_name = format_name(@modules.last)
108
- plugin_slug = Filters.sluggify(@options['name'])
109
- depth = @module_file.count('/') - 1
117
+ depth = @settings[:module_path].count('/')
110
118
  assets_path = ("../" * depth) + 'assets'
111
- type = @options['theme'] ? 'theme' : 'plugin'
112
119
 
113
120
  config = <<-HERE
114
- name: "#{plugin_name}",
115
- slug: "#{plugin_slug}",
121
+ name: "#{@settings[:module_name]}",
122
+ slug: "#{@settings[:name]}",
116
123
  assets_path: File.expand_path(File.join(File.dirname(__FILE__), "#{assets_path}")),
117
- type: "#{type}",
118
- version: #{@mod_path}::VERSION,
124
+ type: "#{@settings[:type]}",
125
+ version: #{@settings[:version]},
119
126
  description: "",
120
127
  website: ""
121
128
  HERE
122
129
  config.rstrip
123
130
  end
124
131
 
132
+ # Creates a blank Jekyll site for testing out a new plugin
133
+ #
125
134
  def self.add_demo_files
126
- dir = File.join(@options['name'], 'demo')
127
- Jekyll::Commands::New.process([dir], {blank: true})
135
+ demo_dir = File.join(@settings[:path], 'demo')
128
136
 
129
- gemfile = <<-HERE
137
+ dirs = %w{_layouts _posts}.map! do |d|
138
+ File.join(demo_dir, d)
139
+ end
140
+
141
+ create_empty_dirs dirs
142
+
143
+ index = File.join(demo_dir, 'index.html')
144
+ action = File.exist?(index) ? "exists".rjust(12).blue.bold : "create".rjust(12).green.bold
145
+ FileUtils.touch index
146
+ puts "#{action} #{index}"
147
+
148
+ gemfile_path = File.join(demo_dir, 'Gemfile')
149
+ gemfile_content = <<-HERE
130
150
  source 'https://rubygems.org'
131
151
 
132
152
  group :octopress do
133
153
  gem 'octopress'
134
- gem '#{@options['name']}', path: '../'
154
+ gem '#{@settings[:name]}', path: '../'
135
155
  end
136
156
  HERE
137
157
 
138
- File.open(File.join(dir, 'Gemfile'), 'w+') {|f| f.write(gemfile) }
158
+ write(gemfile_path, gemfile_content)
159
+
160
+ config_path = File.join(demo_dir, '_config.yml')
161
+ config_content = "exclude:\n - Gemfile*"
162
+
163
+ write(config_path, config_content)
139
164
  end
140
165
 
141
- def self.indent(input, level=1)
142
- input.gsub(/^/, ' ' * level)
166
+ def self.write(path, contents)
167
+ action = File.exist?(path) ? "written".rjust(12).blue.bold : "create".rjust(12).green.bold
168
+
169
+ File.open(path, 'w+') do |f|
170
+ f.write(contents)
171
+ end
172
+ puts "#{action} #{path}"
143
173
  end
174
+
175
+ def self.create_empty_dirs(dirs)
176
+ dirs.each do |d|
177
+ dir = File.join(d)
178
+ action = Dir.exist?(dir) ? "exists".rjust(12).blue.bold : "create".rjust(12).green.bold
179
+ FileUtils.mkdir_p dir
180
+ puts "#{action} #{dir}/"
181
+ end
182
+ end
183
+
184
+ # Read gem settings from the gemspec
185
+ #
186
+ def self.gem_settings(gem_path)
187
+ gemspec_path = Dir.glob(File.join(gem_path, "/*.gemspec")).first
188
+
189
+ if gemspec_path.nil?
190
+ raise "No gemspec file found at #{gem_path}/. To create a new plugin use `octopress ink new <PLUGIN_NAME>`"
191
+ end
192
+
193
+ gemspec = File.open(gemspec_path).read
194
+ require_version = gemspec.scan(/require.+version.+$/)[0]
195
+ module_subpath = require_version.scan(/['"](.+)\/version/).flatten[0]
196
+ version = gemspec.scan(/version.+=\s+(.+)$/).flatten[0]
197
+ module_name = format_name(version.split('::')[-2])
198
+
199
+ {
200
+ path: gem_path,
201
+ gemspec: gemspec,
202
+ gemspec_path: gemspec_path,
203
+ spec_var: gemspec.scan(/(\w+)\.name/).flatten[0],
204
+ version: gemspec.scan(/version.+=\s+(.+)$/).flatten[0],
205
+ name: gemspec.scan(/name.+['"](.+)['"]/).flatten[0],
206
+ version: version,
207
+ require_version: require_version,
208
+ module_path: File.join('lib', module_subpath + '.rb'),
209
+ module_name: module_name
210
+ }
211
+ end
212
+
144
213
  # Add spaces between capital letters
145
214
  #
146
215
  def self.format_name(name)
147
216
  name.scan(/.*?[a-z](?=[A-Z]|$)/).join(' ')
148
217
  end
149
218
 
219
+ # Indent each line of a string
220
+ #
221
+ def self.indent(input, level=1)
222
+ input.gsub(/^/, ' ' * level)
223
+ end
224
+
225
+ # Insert a string before a position
226
+ #
150
227
  def self.insert_before(str, pos, input)
151
228
  if pos
152
229
  str[0..(pos - 1)] + input + str[pos..-1]
@@ -4,6 +4,7 @@ module Octopress
4
4
  require 'octopress-ink/commands/list'
5
5
  require 'octopress-ink/commands/copy'
6
6
  require 'octopress-ink/commands/new'
7
+ require 'octopress-ink/commands/init'
7
8
 
8
9
  class Ink < Octopress::Command
9
10
 
@@ -20,6 +21,7 @@ module Octopress
20
21
  List.process_command(c)
21
22
  Copy.process_command(c)
22
23
  New.process_command(c)
24
+ Init.process_command(c)
23
25
  end
24
26
  end
25
27
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'yaml'
2
3
 
3
4
  module Octopress
@@ -5,17 +6,24 @@ module Octopress
5
6
  module Configuration
6
7
  DEFAULTS = {
7
8
  'docs_mode' => false,
8
- 'concat_css' => true,
9
- 'concat_js' => true,
10
- 'stylesheets_dir' => '_stylesheets',
11
- 'javascripts_dir' => '_javascripts',
12
- 'stylesheets' => [],
13
- 'javascripts' => [],
14
- 'disable' => []
9
+ 'combine_css' => true,
10
+ 'compress_css' => true,
11
+ 'combine_js' => true,
12
+ 'compress_js' => true,
13
+ 'disable' => [],
14
+ 'date_format' => 'ordinal',
15
+ 'linkpost' => {
16
+ 'marker' => "→",
17
+ 'marker_position' => 'after'
18
+ },
19
+ 'post' => {
20
+ 'marker' => false,
21
+ 'marker_position' => 'before'
22
+ }
15
23
  }
16
24
 
17
25
  def self.config
18
- @config ||= DEFAULTS.deep_merge(octopress_config)
26
+ @config ||= Jekyll::Utils.deep_merge_hashes(DEFAULTS, octopress_config)
19
27
  end
20
28
 
21
29
  def self.octopress_config
@@ -23,8 +31,8 @@ module Octopress
23
31
  Octopress.config
24
32
  else
25
33
  file = '_octopress.yml'
26
- if File.exist? file
27
- YAML.safe_load(File.open(file).read || {})
34
+ if File.exist?(file)
35
+ SafeYAML.load_file(file) || {}
28
36
  else
29
37
  {}
30
38
  end
@@ -5,7 +5,7 @@ module Octopress
5
5
  # Returns the site's config root or '/' if the config isn't set
6
6
  #
7
7
  def root
8
- root_url = Plugins.site.config['root']
8
+ root_url = Ink.site.config['root']
9
9
  root_url.nil? ? '/' : File.join('/', root_url)
10
10
  end
11
11
 
@@ -52,7 +52,7 @@ module Octopress
52
52
  # e.g. /images/awesome.gif => http://example.com/images/awesome.gif
53
53
  #
54
54
  def full_urls(input)
55
- url = Plugins.site.config['url']
55
+ url = Ink.site.config['url']
56
56
  if url.nil?
57
57
  raise IOError.new "Could not expand urls: Please add your published url to your _config.yml, eg url: http://example.com/"
58
58
  else
@@ -68,7 +68,7 @@ module Octopress
68
68
  # e.g. /images/awesome.gif => http://example.com/images/awesome.gif
69
69
  #
70
70
  def full_url(input)
71
- url = Plugins.site.config['url']
71
+ url = Ink.site.config['url']
72
72
  if url.nil?
73
73
  raise IOError.new "Could not expand url in #{input}: Please add your site's published url to your _config.yml, eg url: http://example.com/"
74
74
  else
@@ -106,7 +106,7 @@ module Octopress
106
106
 
107
107
  # Returns a title cased string based on John Gruber's title case http://daringfireball.net/2008/08/title_case_update
108
108
  def titlecase(input)
109
- input.titlecase
109
+ Octopress::Utils.titlecase!(input)
110
110
  end
111
111
 
112
112
  # Formats a string for use as a css classname, removing illegal characters
@@ -2,9 +2,10 @@ module Octopress
2
2
  module Ink
3
3
  class PluginAssets < Jekyll::Generator
4
4
  def generate(site)
5
- Plugins.register site
5
+ Ink.site = site
6
+ Plugins.register
6
7
  Plugins.add_files
7
- site = Plugins.site
8
+ site = Ink.site
8
9
  end
9
10
  end
10
11
  end
@@ -27,7 +27,7 @@ module Octopress
27
27
  if file =~ /^\.+\//
28
28
  page = context['page']
29
29
  if local_dir = page['dir']
30
- File.expand_path(File.join(local_dir, file))
30
+ File.expand_path(File.join(Ink.site.source, local_dir, file))
31
31
  else
32
32
  local_dir = File.dirname page['path']
33
33
  File.expand_path(File.join(root, local_dir, file))
@@ -44,7 +44,7 @@ module Octopress
44
44
  end
45
45
 
46
46
  def self.site_dir
47
- File.expand_path(Plugins.site.config['destination'])
47
+ File.expand_path(Ink.site.config['destination'])
48
48
  end
49
49
 
50
50
  def self.page_destination(page)
@@ -56,14 +56,14 @@ module Octopress
56
56
  end
57
57
 
58
58
  def self.find_page_by_dest(dest)
59
- Plugins.site.pages.clone.each do |p|
59
+ Ink.site.pages.clone.each do |p|
60
60
  return p if page_destination(p) == dest
61
61
  end
62
62
  return false
63
63
  end
64
64
 
65
65
  def self.remove_page(dest)
66
- Plugins.site.pages.reject! do |p|
66
+ Ink.site.pages.reject! do |p|
67
67
  page_destination(p) == dest
68
68
  end
69
69
  end
@@ -4,17 +4,121 @@ module Jekyll
4
4
 
5
5
  def do_layout(payload, layouts)
6
6
  # The contentblock tags needs access to the converter to process it while rendering.
7
- config = Octopress::Ink::Plugins.config
8
- payload['plugins'] = config['plugins']
9
- payload['theme'] = config['theme']
7
+ payload = Octopress::Ink.payload(payload)
10
8
  payload['converter'] = self.converter
11
- payload['octopress'] = {}
12
- payload['octopress']['version'] = Octopress::Ink.version
13
- if Octopress::Ink.config['docs_mode']
14
- payload['doc_pages'] = Octopress::Ink::Plugins.doc_pages
9
+
10
+ if page = payload['page']
11
+ if type == :post
12
+ payload['page'] = add_post_vars(page)
13
+ end
14
+
15
+ if page['date']
16
+ payload['page']['date_html'] = date_html(page['date'])
17
+ end
15
18
  end
19
+
16
20
  do_layout_orig(payload, layouts)
17
21
  end
22
+
23
+ def add_post_vars(page)
24
+ linkpost = page['external-url']
25
+
26
+ if linkpost
27
+ config = Octopress::Ink.config['linkpost']
28
+ else
29
+ config = Octopress::Ink.config['post']
30
+ end
31
+
32
+ if Octopress::Ink.config['titlecase']
33
+ Octopress::Utils.titlecase!(page['title'])
34
+ end
35
+
36
+ page.merge({
37
+ 'title_text' => title_text(config, page['title']),
38
+ 'title_html' => title_html(config, page['title']),
39
+ 'title_url' => linkpost || page['url'],
40
+ 'linkpost' => !linkpost.nil?
41
+ })
42
+ end
43
+
44
+ def date_html(date)
45
+ "<time class='entry-date' datetime='#{ datetime(date).xmlschema }' pubdate>#{ format_date(date) }</time>"
46
+ end
47
+
48
+ def format_date(date)
49
+ format = Octopress::Ink.config['date_format']
50
+ date = datetime(date)
51
+ if format == 'ordinal'
52
+ ordinalize(date)
53
+ else
54
+ date.strftime(format)
55
+ end
56
+ end
57
+
58
+ # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
59
+ def ordinalize(date)
60
+ date = datetime(date)
61
+ d = "<span class='date-month'>#{date.strftime('%b')}</span> "
62
+ d = "<span class='date-day'>#{date.strftime('%e')}</span> "
63
+ d += "<span class='date-suffix'>#{ordinal_suffix(date)}</span>, "
64
+ d += "<span class='date-year'>#{date.strftime('%Y')}</span>"
65
+ end
66
+
67
+ # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
68
+ def ordinal_suffix(date)
69
+ number = date.strftime('%e').to_i
70
+ if (11..13).include?(number % 100)
71
+ "th"
72
+ else
73
+ case number % 10
74
+ when 1; "st"
75
+ when 2; "nd"
76
+ when 3; "rd"
77
+ else "th"
78
+ end
79
+ end
80
+ end
81
+
82
+ def datetime(input)
83
+ case input
84
+ when Time
85
+ input
86
+ when String
87
+ Time.parse(input) rescue Time.at(input.to_i)
88
+ when Numeric
89
+ Time.at(input)
90
+ else
91
+ raise "Invalid Date:", "'#{input}' is not a valid datetime."
92
+ exit(1)
93
+ end
94
+ end
95
+
96
+
97
+ def title_html(config, title)
98
+ return title if !config['marker']
99
+
100
+ marker = "<span class='post-marker post-marker-#{config['marker_position']}'>#{config['marker']}</span>"
101
+ position = config['marker_position']
102
+
103
+ title = Octopress::Ink::Filters.unorphan(title)
104
+
105
+ if config['marker_position'] == 'before'
106
+ "#{marker} #{title}"
107
+ else
108
+ "#{title} #{marker}"
109
+ end
110
+ end
111
+
112
+ def title_text(config, title)
113
+ return title if !config['marker']
114
+ position = config['marker_position']
115
+
116
+ if config['marker_position'] == 'before'
117
+ "#{config['marker']} #{title}"
118
+ else
119
+ "#{title} #{config['marker']}"
120
+ end
121
+ end
18
122
  end
19
123
 
20
124
  # Create a new page class to allow partials to trigger Jekyll Page Hooks.
@@ -36,4 +140,16 @@ module Jekyll
36
140
  do_layout(payload, { no_layout: nil })
37
141
  end
38
142
  end
143
+
144
+ class Site
145
+ alias_method :write_orig, :write
146
+ # Called after write
147
+
148
+ def write
149
+ write_orig
150
+ Octopress::Ink::Plugins.static_files.each do |f|
151
+ f.write(config['destination'])
152
+ end
153
+ end
154
+ end
39
155
  end
@@ -28,10 +28,12 @@ module Octopress
28
28
  @url
29
29
  else
30
30
  begin
31
- config = @config['page_permalinks'][File.basename(self.name, '.*')]
31
+ config = @config['permalinks'][File.basename(self.name, '.*')]
32
32
  if config.is_a? String
33
33
  @url = config
34
34
  self.data['permalink'] = nil
35
+ else
36
+ @config['permalinks'][File.basename(self.name, '.*')] = self.data['permalink']
35
37
  end
36
38
  rescue; end
37
39