octopress-ink 1.0.0.alpha.31 → 1.0.0.alpha.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/octopress-ink.rb +92 -37
  3. data/lib/octopress-ink/assets.rb +12 -10
  4. data/lib/octopress-ink/assets/asset.rb +91 -80
  5. data/lib/octopress-ink/assets/config.rb +29 -27
  6. data/lib/octopress-ink/assets/include.rb +11 -9
  7. data/lib/octopress-ink/assets/javascript.rb +7 -4
  8. data/lib/octopress-ink/assets/layout.rb +16 -11
  9. data/lib/octopress-ink/assets/page.rb +32 -30
  10. data/lib/octopress-ink/assets/root.rb +17 -15
  11. data/lib/octopress-ink/assets/sass.rb +48 -46
  12. data/lib/octopress-ink/assets/stylesheet.rb +25 -23
  13. data/lib/octopress-ink/commands.rb +23 -0
  14. data/lib/octopress-ink/commands/helpers.rb +19 -0
  15. data/lib/octopress-ink/commands/info.rb +24 -0
  16. data/lib/octopress-ink/filters.rb +112 -109
  17. data/lib/octopress-ink/generators/plugin_assets.rb +8 -6
  18. data/lib/octopress-ink/helpers.rb +7 -5
  19. data/lib/octopress-ink/helpers/conditional.rb +16 -14
  20. data/lib/octopress-ink/helpers/content_for.rb +23 -20
  21. data/lib/octopress-ink/helpers/path.rb +51 -48
  22. data/lib/octopress-ink/helpers/var.rb +82 -80
  23. data/lib/octopress-ink/jekyll/hooks.rb +2 -2
  24. data/lib/octopress-ink/jekyll/page.rb +38 -35
  25. data/lib/octopress-ink/jekyll/static_file.rb +18 -16
  26. data/lib/octopress-ink/jekyll/static_file_content.rb +8 -6
  27. data/lib/octopress-ink/plugin.rb +189 -144
  28. data/lib/octopress-ink/plugins.rb +249 -230
  29. data/lib/octopress-ink/plugins/stylesheets.rb +37 -35
  30. data/lib/octopress-ink/tags.rb +16 -14
  31. data/lib/octopress-ink/tags/abort.rb +15 -12
  32. data/lib/octopress-ink/tags/assign.rb +21 -19
  33. data/lib/octopress-ink/tags/capture.rb +26 -24
  34. data/lib/octopress-ink/tags/content_for.rb +15 -12
  35. data/lib/octopress-ink/tags/filter.rb +16 -13
  36. data/lib/octopress-ink/tags/include.rb +40 -38
  37. data/lib/octopress-ink/tags/javascript.rb +6 -4
  38. data/lib/octopress-ink/tags/line_comment.rb +6 -3
  39. data/lib/octopress-ink/tags/render.rb +53 -51
  40. data/lib/octopress-ink/tags/return.rb +12 -9
  41. data/lib/octopress-ink/tags/stylesheet.rb +6 -4
  42. data/lib/octopress-ink/tags/wrap.rb +62 -60
  43. data/lib/octopress-ink/tags/yield.rb +23 -20
  44. data/lib/octopress-ink/version.rb +1 -1
  45. data/octopress-ink.gemspec +1 -1
  46. data/test/Gemfile +3 -2
  47. data/test/_config.yml +2 -0
  48. data/test/plugins/awesome-sauce/plugin.rb +3 -2
  49. data/test/plugins/test-theme/plugin.rb +3 -2
  50. metadata +7 -4
@@ -1,10 +1,12 @@
1
1
  module Octopress
2
- class PluginAssets < Jekyll::Generator
3
- def generate(site)
4
- Plugins.site = site
5
- Plugins.register_layouts
6
- Plugins.add_static_files
7
- site = Plugins.site
2
+ module Ink
3
+ class PluginAssets < Jekyll::Generator
4
+ def generate(site)
5
+ Plugins.site = site
6
+ Plugins.register_layouts
7
+ Plugins.add_static_files
8
+ site = Plugins.site
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,8 +1,10 @@
1
1
  module Octopress
2
- module Helpers
3
- autoload :Conditional, 'octopress-ink/helpers/conditional'
4
- autoload :ContentFor, 'octopress-ink/helpers/content_for'
5
- autoload :Path, 'octopress-ink/helpers/path'
6
- autoload :Var, 'octopress-ink/helpers/var'
2
+ module Ink
3
+ module Helpers
4
+ autoload :Conditional, 'octopress-ink/helpers/conditional'
5
+ autoload :ContentFor, 'octopress-ink/helpers/content_for'
6
+ autoload :Path, 'octopress-ink/helpers/path'
7
+ autoload :Var, 'octopress-ink/helpers/var'
8
+ end
7
9
  end
8
10
  end
@@ -1,22 +1,24 @@
1
1
  module Octopress
2
- module Helpers
3
- module Conditional
4
- SYNTAX = /(.*)\s(if|unless)\s(.+)/
2
+ module Ink
3
+ module Helpers
4
+ module Conditional
5
+ SYNTAX = /(.*)\s(if|unless)\s(.+)/
5
6
 
6
- def self.parse(markup, context)
7
- if markup =~ SYNTAX
8
- case $2
9
- when 'if'
10
- tag = Liquid::If.new('if', $3, ["true","{% endif %}"])
11
- when 'unless'
12
- tag = Liquid::Unless.new('unless', $3, ["true","{% endunless %}"])
7
+ def self.parse(markup, context)
8
+ if markup =~ SYNTAX
9
+ case $2
10
+ when 'if'
11
+ tag = Liquid::If.new('if', $3, ["true","{% endif %}"])
12
+ when 'unless'
13
+ tag = Liquid::Unless.new('unless', $3, ["true","{% endunless %}"])
14
+ end
15
+ tag.render(context) != '' ? $1 : false
16
+ else
17
+ markup
13
18
  end
14
- tag.render(context) != '' ? $1 : false
15
- else
16
- markup
17
19
  end
18
- end
19
20
 
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,29 +1,32 @@
1
1
  module Octopress
2
- module Helpers
3
- module ContentFor
4
- def self.get_block_name(tag_name, markup)
5
- if markup.strip == ''
6
- raise IOError.new "Syntax Error: #{tag_name} requires a name, eg. {% #{tag_name} sidebar %}"
7
- else
8
- markup.strip
2
+ module Ink
3
+ module Helpers
4
+ module ContentFor
5
+ def self.get_block_name(tag_name, markup)
6
+ if markup.strip == ''
7
+ raise IOError.new "Syntax Error: #{tag_name} requires a name, eg. {% #{tag_name} sidebar %}"
8
+ else
9
+ markup.strip
10
+ end
9
11
  end
10
- end
11
12
 
12
- # Gets the storage space for the content block
13
- def self.get_block(context, block)
14
- context.environments.first['content_for'] ||= {}
15
- context.environments.first['content_for'][block] ||= []
16
- end
13
+ # Gets the storage space for the content block
14
+ def self.get_block(context, block)
15
+ context.environments.first['content_for'] ||= {}
16
+ context.environments.first['content_for'][block] ||= []
17
+ end
17
18
 
18
- def self.render(context, block)
19
- content = get_block(context, block).map { |b| b }.join
20
- end
19
+ def self.render(context, block)
20
+ content = get_block(context, block).map { |b| b }.join
21
+ end
21
22
 
22
- def self.append_to_block(context, block, content)
23
- converter = context.environments.first['converter']
24
- content = converter.convert(content).sub(/\n$/,'')
25
- get_block(context, block) << content
23
+ def self.append_to_block(context, block, content)
24
+ converter = context.environments.first['converter']
25
+ content = converter.convert(content).sub(/\n$/,'')
26
+ get_block(context, block) << content
27
+ end
26
28
  end
27
29
  end
28
30
  end
29
31
  end
32
+
@@ -1,66 +1,69 @@
1
1
  module Octopress
2
- module Helpers
3
- module Path
4
- FILE = /(\S+)(\s?)(.*)/
5
- def self.parse(markup, context)
6
- if markup =~ FILE
7
- (context[$1].nil? ? $1 : context[$1]) + ' ' + ($3 || '')
8
- else
9
- markup
2
+ module Ink
3
+ module Helpers
4
+ module Path
5
+ FILE = /(\S+)(\s?)(.*)/
6
+ def self.parse(markup, context)
7
+ if markup =~ FILE
8
+ (context[$1].nil? ? $1 : context[$1]) + ' ' + ($3 || '')
9
+ else
10
+ markup
11
+ end
10
12
  end
11
- end
12
13
 
13
- # Allow paths to begin from the directory of the context page or
14
- # have absolute paths
15
- #
16
- # Input:
17
- # - file: "file.html"
18
- # - context: A Jekyll context object
19
- #
20
- # Returns the full path to a file
21
- #
22
- def self.expand(file, context)
23
- root = context.registers[:site].source
14
+ # Allow paths to begin from the directory of the context page or
15
+ # have absolute paths
16
+ #
17
+ # Input:
18
+ # - file: "file.html"
19
+ # - context: A Jekyll context object
20
+ #
21
+ # Returns the full path to a file
22
+ #
23
+ def self.expand(file, context)
24
+ root = context.registers[:site].source
24
25
 
25
- # If local file, e.g. ./somefile
26
- if file =~ /^\.\/(.+)/
27
- local_dir = File.dirname context.registers[:page]['path']
28
- File.join root, local_dir, $1
26
+ # If local file, e.g. ./somefile
27
+ if file =~ /^\.\/(.+)/
28
+ local_dir = File.dirname context.registers[:page]['path']
29
+ File.join root, local_dir, $1
29
30
 
30
- # If absolute or relative to a user directory, e.g. /Users/Bob/somefile or ~/somefile
31
- elsif file =~ /^[\/~]/
32
- Pathname.new(file).expand_path
31
+ # If absolute or relative to a user directory, e.g. /Users/Bob/somefile or ~/somefile
32
+ elsif file =~ /^[\/~]/
33
+ Pathname.new(file).expand_path
33
34
 
34
- # Otherwise, assume relative to site root
35
- else
36
- File.join root, file
35
+ # Otherwise, assume relative to site root
36
+ else
37
+ File.join root, file
38
+ end
37
39
  end
38
- end
39
40
 
40
- def self.site_dir
41
- File.expand_path(Plugins.site.config['destination'])
42
- end
41
+ def self.site_dir
42
+ File.expand_path(Plugins.site.config['destination'])
43
+ end
43
44
 
44
- def self.page_destination(page)
45
- page.destination(site_dir)
46
- end
45
+ def self.page_destination(page)
46
+ page.destination(site_dir)
47
+ end
47
48
 
48
- def self.find_page(page)
49
- find_page_by_dest page_destination(page)
50
- end
49
+ def self.find_page(page)
50
+ find_page_by_dest page_destination(page)
51
+ end
51
52
 
52
- def self.find_page_by_dest(dest)
53
- Plugins.site.pages.clone.each do |p|
54
- return p if page_destination(p) == dest
53
+ def self.find_page_by_dest(dest)
54
+ Plugins.site.pages.clone.each do |p|
55
+ return p if page_destination(p) == dest
56
+ end
57
+ return false
55
58
  end
56
- return false
57
- end
58
59
 
59
- def self.remove_page(dest)
60
- Plugins.site.pages.reject! do |p|
61
- page_destination(p) == dest
60
+ def self.remove_page(dest)
61
+ Plugins.site.pages.reject! do |p|
62
+ page_destination(p) == dest
63
+ end
62
64
  end
63
65
  end
64
66
  end
65
67
  end
66
68
  end
69
+
@@ -1,99 +1,101 @@
1
1
  module Octopress
2
- module Helpers
3
- module Var
4
- TERNARY = /(.*?)\(\s*(.+?)\s+\?\s+(.+?)\s+:\s+(.+?)\s*\)(.+)?/
5
- HAS_FILTERS = /(.*?)(\s+\|\s+.+)/
2
+ module Ink
3
+ module Helpers
4
+ module Var
5
+ TERNARY = /(.*?)\(\s*(.+?)\s+\?\s+(.+?)\s+:\s+(.+?)\s*\)(.+)?/
6
+ HAS_FILTERS = /(.*?)(\s+\|\s+.+)/
6
7
 
7
- def self.set_var(var, operator, value, context)
8
- case operator
9
- when '||='
10
- context.scopes.last[var] = value if context.scopes.last[var].nil?
11
- when '+='
12
- if context.scopes.last[var].nil?
13
- context.scopes.last[var] = value
8
+ def self.set_var(var, operator, value, context)
9
+ case operator
10
+ when '||='
11
+ context.scopes.last[var] = value if context.scopes.last[var].nil?
12
+ when '+='
13
+ if context.scopes.last[var].nil?
14
+ context.scopes.last[var] = value
15
+ else
16
+ context.scopes.last[var] += value
17
+ end
14
18
  else
15
- context.scopes.last[var] += value
19
+ context.scopes.last[var] = value
16
20
  end
17
- else
18
- context.scopes.last[var] = value
21
+ context
19
22
  end
20
- context
21
- end
22
23
 
23
- def self.get_value(vars, context)
24
- vars = evaluate_ternary(vars, context)
25
- vars = vars.strip.gsub(/ or /, ' || ')
26
- filters = false
27
- if vars =~ HAS_FILTERS
28
- vars = $1
29
- filters = $2
30
- end
31
- vars = vars.split(/ \|\| /).map { |v|
32
- context[v.strip]
33
- }.compact
24
+ def self.get_value(vars, context)
25
+ vars = evaluate_ternary(vars, context)
26
+ vars = vars.strip.gsub(/ or /, ' || ')
27
+ filters = false
28
+ if vars =~ HAS_FILTERS
29
+ vars = $1
30
+ filters = $2
31
+ end
32
+ vars = vars.split(/ \|\| /).map { |v|
33
+ context[v.strip]
34
+ }.compact
34
35
 
35
- var = vars.first
36
- if filters
37
- var = Liquid::Variable.new("'#{var}'"+ filters).render(context)
36
+ var = vars.first
37
+ if filters
38
+ var = Liquid::Variable.new("'#{var}'"+ filters).render(context)
39
+ end
40
+ var
38
41
  end
39
- var
40
- end
41
42
 
42
- def self.evaluate_ternary(markup, context)
43
- if markup =~ TERNARY
44
- $1 + (Conditional.parse(" if #{$2}", context) ? $3 : $4) + $5
45
- else
46
- markup
43
+ def self.evaluate_ternary(markup, context)
44
+ if markup =~ TERNARY
45
+ $1 + (Conditional.parse(" if #{$2}", context) ? $3 : $4) + $5
46
+ else
47
+ markup
48
+ end
47
49
  end
48
- end
49
50
 
50
- # Parses filters into arrays
51
- #
52
- # input - a string of one or more filters, e.g. "| upcase | replace:'a','b'"
53
- #
54
- # Returns nested arrays of filters and arguments
55
- #
56
- def self.parse_filters(input)
57
- output = []
58
- if input.match(/#{Liquid::FilterSeparator}\s*(.*)/o)
59
- filters = Regexp.last_match(1).scan(Liquid::Variable::FilterParser)
60
- filters.each do |f|
61
- if matches = f.match(/\s*(\w+)/)
62
- filtername = matches[1]
63
- filterargs = f.scan(/(?:#{Liquid::FilterArgumentSeparator}|#{Liquid::ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{Liquid::QuotedFragment})/o).flatten
64
- output << [filtername, filterargs]
51
+ # Parses filters into arrays
52
+ #
53
+ # input - a string of one or more filters, e.g. "| upcase | replace:'a','b'"
54
+ #
55
+ # Returns nested arrays of filters and arguments
56
+ #
57
+ def self.parse_filters(input)
58
+ output = []
59
+ if input.match(/#{Liquid::FilterSeparator}\s*(.*)/o)
60
+ filters = Regexp.last_match(1).scan(Liquid::Variable::FilterParser)
61
+ filters.each do |f|
62
+ if matches = f.match(/\s*(\w+)/)
63
+ filtername = matches[1]
64
+ filterargs = f.scan(/(?:#{Liquid::FilterArgumentSeparator}|#{Liquid::ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{Liquid::QuotedFragment})/o).flatten
65
+ output << [filtername, filterargs]
66
+ end
65
67
  end
66
68
  end
69
+ output
67
70
  end
68
- output
69
- end
70
71
 
71
- # Passes input through Liquid filters
72
- #
73
- # content - a string to be parsed
74
- # filters - a series of liquid filters e.g. "| upcase | replace:'a','b'"
75
- # context - the current Liquid context object
76
- #
77
- # Returns a filtered string
78
- #
79
- def self.render_filters(content, filters, context)
80
- filters = parse_filters(filters)
81
- return '' if content.nil?
82
- filters.inject(content) do |output, filter|
83
- filterargs = []
84
- keyword_args = {}
85
- filter[1].to_a.each do |a|
86
- if matches = a.match(/\A#{Liquid::TagAttributes}\z/o)
87
- keyword_args[matches[1]] = context[matches[2]]
88
- else
89
- filterargs << context[a]
72
+ # Passes input through Liquid filters
73
+ #
74
+ # content - a string to be parsed
75
+ # filters - a series of liquid filters e.g. "| upcase | replace:'a','b'"
76
+ # context - the current Liquid context object
77
+ #
78
+ # Returns a filtered string
79
+ #
80
+ def self.render_filters(content, filters, context)
81
+ filters = parse_filters(filters)
82
+ return '' if content.nil?
83
+ filters.inject(content) do |output, filter|
84
+ filterargs = []
85
+ keyword_args = {}
86
+ filter[1].to_a.each do |a|
87
+ if matches = a.match(/\A#{Liquid::TagAttributes}\z/o)
88
+ keyword_args[matches[1]] = context[matches[2]]
89
+ else
90
+ filterargs << context[a]
91
+ end
92
+ end
93
+ filterargs << keyword_args unless keyword_args.empty?
94
+ begin
95
+ output = context.invoke(filter[0], output, *filterargs)
96
+ rescue
97
+ raise "Error - filter '#{filter[0]}' could not be found."
90
98
  end
91
- end
92
- filterargs << keyword_args unless keyword_args.empty?
93
- begin
94
- output = context.invoke(filter[0], output, *filterargs)
95
- rescue
96
- raise "Error - filter '#{filter[0]}' could not be found."
97
99
  end
98
100
  end
99
101
  end
@@ -4,12 +4,12 @@ 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::Plugins.config
7
+ config = Octopress::Ink::Plugins.config
8
8
  payload['plugins'] = config['plugins']
9
9
  payload['theme'] = config['theme']
10
10
  payload['converter'] = self.converter
11
11
  payload['octopress'] = {}
12
- payload['octopress']['version'] = Octopress.version
12
+ payload['octopress']['version'] = Octopress::Ink.version
13
13
  do_layout_orig(payload, layouts)
14
14
  end
15
15
  end
@@ -1,45 +1,48 @@
1
1
  module Octopress
2
- class Page < Jekyll::Page
2
+ module Ink
3
+ class Page < Jekyll::Page
3
4
 
4
- # Override the destination for a page
5
- #
6
- # url - Path relative to destination directory.
7
- # examples:
8
- # - '/' for the _site/index.html page
9
- # - '/archive/' for the _site/archive/index.html page
10
- #
11
- def initialize(site, base, dir, name, config)
12
- @plugin_config = config
13
- super(site, base, dir, name)
14
- end
5
+ # Override the destination for a page
6
+ #
7
+ # url - Path relative to destination directory.
8
+ # examples:
9
+ # - '/' for the _site/index.html page
10
+ # - '/archive/' for the _site/archive/index.html page
11
+ #
12
+ def initialize(site, base, dir, name, config)
13
+ @plugin_config = config
14
+ super(site, base, dir, name)
15
+ end
15
16
 
16
- def destination(dest)
17
- path = File.join(dest, self.url)
18
- if self.url =~ /\/$/
19
- if self.ext == '.xml'
20
- path = File.join(path, "index.xml")
21
- else
22
- path = File.join(path, "index.html")
17
+ def destination(dest)
18
+ path = File.join(dest, self.url)
19
+ if self.url =~ /\/$/
20
+ if self.ext == '.xml'
21
+ path = File.join(path, "index.xml")
22
+ else
23
+ path = File.join(path, "index.html")
24
+ end
23
25
  end
26
+ path
24
27
  end
25
- path
26
- end
27
28
 
28
- # Allow pages to read url from plugin configuration
29
- #
30
- def url
31
- if @url
32
- @url
33
- else
34
- begin
35
- if path_config = self.data['url_config']
36
- config = @plugin_config
37
- path_config.split('.').each { |key| config = config[key] }
38
- @url = config if config.is_a? String
39
- end
40
- rescue; end
41
- super
29
+ # Allow pages to read url from plugin configuration
30
+ #
31
+ def url
32
+ if @url
33
+ @url
34
+ else
35
+ begin
36
+ if path_config = self.data['url_config']
37
+ config = @plugin_config
38
+ path_config.split('.').each { |key| config = config[key] }
39
+ @url = config if config.is_a? String
40
+ end
41
+ rescue; end
42
+ super
43
+ end
42
44
  end
43
45
  end
44
46
  end
45
47
  end
48
+