textigniter 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -56,6 +56,12 @@ These text files are broken down into a meta section and sections delimited by @
56
56
 
57
57
  The following variables would be available in the template according to the code above: {{ title }}, {{ slug }}, {{ tags }}, {{ author }}, {{ content }}, {{ sidebar }}.
58
58
 
59
+ h2. Plugins
60
+
61
+ Textigniter supports _meta_ custom plugins. You can add custom plugin code to this folder. Plugins are named after their _meta_ keys found in _.textile_ files.
62
+
63
+ For example, if you had a meta key named twitter, you would create a twitter.rb file inside of this directory with a class declaration of @class Textigniter::Plugins::Twitter@. The plugin must have a @parse(value)@ method and must return the parsed value, i.e @return value@
64
+
59
65
  h2. Templates
60
66
 
61
67
  Textigniter uses _liquid_ templates. Anything that goes in liquid can go in textigniter. Checkout the "liquid documentation.":https://github.com/Shopify/liquid/wiki/Liquid-for-Designers
@@ -2,4 +2,4 @@ h1. Textigniter
2
2
 
3
3
  Welcome to your Textigniter environment. This is pretty simple.
4
4
 
5
- There are two folders. [.textigniter] is where you'll store the source for your site. [output] is where textigniter builds the static output of yoursite.
5
+ There are three folders. [.textigniter] is where you'll store the source for your site. [output] is where textigniter builds the static output of yoursite. [plugins] is for your custom meta plugins.
@@ -4,6 +4,7 @@ site_description: "A textigniter powered website"
4
4
  copyright: "2011 © Textigniter"
5
5
 
6
6
  # textigniter configuration
7
- blog_type: article
7
+ blog_type: "article"
8
8
  output_environment: "output"
9
- text_parser: textile
9
+ plugins_environment: "plugins"
10
+ text_parser: "textile"
@@ -0,0 +1,5 @@
1
+ h1. Custom Plugins
2
+
3
+ Textigniter supports _meta_ custom plugins. You can add custom plugin code to this folder. Plugins are named after their _meta_ keys found in _.textile_ files.
4
+
5
+ For example, if you had a meta key named twitter, you would create a twitter.rb file inside of this directory with a class declaration of @class Textigniter::Plugins::Twitter@. The plugin must have a @parse(value)@ method and must return the parsed value, i.e @return value@
@@ -17,7 +17,7 @@ class Textigniter::Build::RenderFiles
17
17
  # Switch based on format and build a filename
18
18
  case format
19
19
  when 'html'
20
- filename = item['directory'] + 'index.html'
20
+ filename = item['directory'] + '/index.html'
21
21
  when 'css'
22
22
  filename = item['directory'] + '/' + item['filename'] + '.css'
23
23
  when 'js'
@@ -1,101 +1,92 @@
1
1
  # this is the script parser
2
2
  class Textigniter::Build::TextParser
3
+
4
+ def plugins
5
+ @plugins = Textigniter::Plugins.new
6
+ end
3
7
 
4
8
  # parse the text and build a hash to send to template rendering
5
9
  def process(build_list)
6
10
  # Output message
7
- STDOUT.puts "Parsing ".yellow_on_black + "[#{$config['text_parser']}]".blue_on_black + " content ".yellow_on_black + "[OK]".green_on_black
11
+ STDOUT.puts "Parsing ".yellow_on_black + "[#{$config['text_parser']}]".blue_on_black + " content ".yellow_on_black + "[OK]".green_on_black
12
+ # parse for plugins
13
+ plugin_parser = Textigniter::Plugins.new
8
14
  # create array to store processed items in
9
15
  items = Array.new
10
16
  # create an articles array for blog items
11
17
  articles = Array.new
12
18
  # go through the build list and process
13
19
  build_list.each do |f|
20
+
14
21
  # open the file for reading
15
22
  file = File.open(f, 'rb')
23
+
16
24
  # store the contents in contents and split it at --
17
25
  contents = file.read
18
26
  components = contents.split('--')
27
+
19
28
  # load the config from the text file
20
29
  meta = YAML::load(components[0])
30
+
21
31
  # create a new hash to work with
22
32
  @h = Hash.new
33
+
23
34
  # parse through the meta
24
35
  meta.each do |m|
25
36
  @h[m[0]] = m[1]
26
37
  end
38
+
27
39
  # add config to the mix
28
40
  $config.each do |c|
29
41
  @h[c[0]] = c[1]
30
42
  end
31
- # process for a created_at
32
- unless @h.has_key? 'created_at'
33
- # string to test agains
34
- created_at = File.basename(f, '.textile')[0..9]
35
- # is this a valid date?
36
- valid = Date.parse(created_at) rescue false
37
- if valid
38
- @h['created_at'] = created_at
39
- end
40
- end
41
- # get the slug if it exists else calculate
42
- unless @h.has_key? 'slug'
43
- # if no created_at, no need to fix
44
- if @h['created_at'].nil?
45
- @h['slug'] = File.basename(f, '.textile')
46
- # fix the slug
47
- else
48
- @h['slug'] = File.basename(f, '.textile').gsub(@h['created_at'][0..9] + "-", '')
49
- end
50
- end
51
- # the write directory
52
- directory = File.dirname(f).sub($twd,$owd) + '/' + @h['slug']
53
- directory = directory.sub("#{$config['output_environment']}/content", "#{$config['output_environment']}")
54
- directory = directory.sub("#{$config['output_environment']}/index", "#{$config['output_environment']}") + '/'
55
- @h['directory'] = directory
43
+
44
+ # created_at key
45
+ @h['created_at'] = File.basename(f, ".#{$config['text_parser']}")[0..9] unless @h.has_key? 'created_at'
46
+
47
+ # slug key
48
+ @h['slug'] = "#{File.dirname(f)}/#{File.basename(f, ".#{$config['text_parser']}")}" unless @h.has_key? 'slug'
49
+
56
50
  # get the template if exists else default
57
- unless @h.has_key? 'template'
58
- @h['template'] = 'default'
59
- end
51
+ @h['template'] = 'default' unless @h.has_key? 'template'
52
+
60
53
  # gather the rest of the components into key value and convert
61
- components[1..-1].each do |component|
62
- # split into key value
63
- kv = component.split("\n", 2)
64
- # do some cleanup
65
- key = kv[0].strip
66
- content = parse(kv[1].strip)
67
- # store into the list
68
- @h[key] = content
69
- end
70
- # check if blog_type
54
+ @h = components_parser(components, @h)
55
+
56
+ # run through plugin parser
57
+ @h = plugin_parser.parse(@h)
58
+
59
+ # set slug to directory
60
+ @h['directory'] = @h['slug']
61
+
62
+ # delete the slug key after its been renamed to directory
63
+ @h.delete("slug")
64
+
65
+ # check if blog posts according to the type key
66
+ # I feel like there is probably a better way to do this.
71
67
  if @h.has_key? 'type'
72
68
  if @h['type'] == $config['blog_type']
73
69
  articles.push @h
74
70
  end
75
71
  end
72
+
76
73
  # push processed item onto the array
77
74
  items.push @h
78
75
  end
76
+
79
77
  # create a super object to pass
80
78
  @results = Hash.new
79
+
81
80
  # store files to process
82
81
  @results['items'] = items
82
+
83
83
  # store blog posts to separate key
84
84
  @results['articles'] = articles
85
- # process blog articles
86
- # process_blog(articles)
85
+
87
86
  # return the items
88
87
  return @results
89
88
  end
90
-
91
- # process blog articles
92
- def process_blog(articles)
93
- # iterate through articles
94
- articles.each do |article|
95
- # puts "#{article['title']}"
96
- end
97
- end
98
-
89
+
99
90
  # parse text
100
91
  def parse(content)
101
92
  case $config['text_parser']
@@ -120,7 +111,24 @@ class Textigniter::Build::TextParser
120
111
  end
121
112
  end
122
113
 
114
+ # split out components to key/value pairs
115
+ def components_parser(components, h)
116
+ # iterate through components
117
+ components[1..-1].each do |component|
118
+ # split into key value
119
+ kv = component.split("\n", 2)
120
+ # do some cleanup
121
+ key = kv[0].strip
122
+ content = parse(kv[1].strip)
123
+ # store into the list
124
+ h[key] = content
125
+ end
126
+ # return h
127
+ return h
128
+ end
129
+
123
130
  end
124
131
 
125
132
  # requirements
126
- require 'date'
133
+ require 'date'
134
+ require_relative '../plugins'
@@ -0,0 +1,17 @@
1
+ class Textigniter::Plugins::CreatedAt
2
+
3
+ def parse(value)
4
+ # is this a valid date?
5
+ valid = Date.parse(value) rescue false
6
+ # if valid, pass value back
7
+ if valid != false
8
+ created_at = value
9
+ # if invalid, pass nil
10
+ else
11
+ created_at = nil
12
+ end
13
+ # return the parsed value
14
+ return created_at
15
+ end
16
+
17
+ end
@@ -0,0 +1,37 @@
1
+ class Textigniter::Plugins::Slug
2
+
3
+ def parse(value)
4
+
5
+ # split the value by /
6
+ values = value.split(/\//)
7
+ # get the filename
8
+ filename = values.last
9
+ # values pop
10
+ values.pop
11
+
12
+ # check for date in slug
13
+ valid = Date.parse(filename[0..9]) rescue false
14
+
15
+ # slug does contain date
16
+ if valid != false
17
+ slug = "#{values.join('/')}/#{filename.gsub(filename[0..9] + "-", '')}"
18
+ # slug does not contain date
19
+ else
20
+ slug = value
21
+ end
22
+
23
+ # check for path name
24
+ slug = "#{$owd}/#{slug}" unless slug.include? $twd
25
+
26
+ # check for content/index
27
+ slug = slug.sub('content/index', 'content')
28
+
29
+ # replace twd with owd
30
+ slug = slug.sub("#{$twd}/content", "#{$owd}")
31
+
32
+ # return parsed slug
33
+ return slug
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,12 @@
1
+ class Textigniter::Plugins::Tags
2
+
3
+ def initialize
4
+
5
+ end
6
+
7
+ def parse(value)
8
+
9
+ return value
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ class Textigniter::Plugins::Twitter
2
+
3
+ def initialize
4
+
5
+ end
6
+
7
+ def parse(value)
8
+
9
+ return value
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ class Textigniter::Plugins::Type
2
+
3
+ def initialize
4
+
5
+ end
6
+
7
+ def parse(value)
8
+
9
+ return value
10
+ end
11
+
12
+ end
@@ -0,0 +1,66 @@
1
+ class Textigniter::Plugins
2
+
3
+ # parse through the hash
4
+ def parse(h)
5
+ # create a hash to store processed items
6
+ @h = Hash.new
7
+ # require plugins
8
+ require_plugins(plugins)
9
+ # load plugins
10
+ splugin = load_plugins(plugins)
11
+ # iterate through the hash
12
+ h.each do |key, value|
13
+ # check for plugin methods
14
+ if splugin.has_key?(key)
15
+ @h["#{key}"] = splugin["#{key}"].parse(value)
16
+ else
17
+ @h["#{key}"] = value
18
+ end
19
+ end
20
+ # return the hash
21
+ return @h
22
+ end
23
+
24
+ # gather a list of textigniter and custom plugins
25
+ def plugins
26
+ # textigniter plugins
27
+ textigniter_plugins = Dir.glob("#{File.dirname(__FILE__)}/plugins/**/*.rb")
28
+ # custom plugins
29
+ custom_plugins = Dir.glob("#{Dir::pwd}/plugins/**/*.rb")
30
+ # join plugins
31
+ @plugins = textigniter_plugins | custom_plugins
32
+ end
33
+
34
+ # require the plugins for use
35
+ def require_plugins(plugins)
36
+ plugins.each do |plugin|
37
+ # require the plugin
38
+ require_relative plugin
39
+ end
40
+ end
41
+
42
+ # load the plugins and return a super object
43
+ def load_plugins(plugins)
44
+ # create a hash to store plugins in
45
+ splugin = Hash.new
46
+ # iterate through list
47
+ plugins.each do |plugin|
48
+ # buld the class name
49
+ classname = camelcase(File.basename(plugin, '.rb'))
50
+ # load the class
51
+ loaded_class = eval("Textigniter::Plugins::#{classname}").new
52
+ # add it to splugin
53
+ splugin["#{File.basename(plugin, '.rb')}"] = loaded_class
54
+ end
55
+ # return the super plugin
56
+ return splugin
57
+ end
58
+
59
+ def camelcase(phrase)
60
+ phrase.gsub!(/_/, ' ')
61
+ phrase.gsub!(/\b\w/){$&.upcase}
62
+ phrase.gsub!(/ /, '')
63
+ return phrase
64
+ end
65
+
66
+ end
@@ -3,7 +3,7 @@
3
3
  # that you have added to the public_html folder so be sure to back those up.
4
4
  class Textigniter::Scrub
5
5
 
6
- def initialize
6
+ def initialize(args)
7
7
  # Output start message
8
8
  STDOUT.puts "Scrubbing textigniter environment".yellow_on_black
9
9
  # Check for an existing environment
@@ -21,6 +21,7 @@ class Textigniter::Scrub
21
21
  cwd = Dir::pwd + '/'
22
22
  # Scrub the directory, no turning back
23
23
  scrub_directory(cwd + '.textigniter')
24
+ scrub_directory(cwd + 'plugins')
24
25
  scrub_directory(cwd + "#{$config['output_environment']}")
25
26
  # Files to delete as well
26
27
  files = [ cwd + "README.textile", cwd + "config.yml" ]
data/lib/textigniter.rb CHANGED
@@ -14,7 +14,7 @@ class Textigniter
14
14
  # Contains a switch for arguments passed via the command line
15
15
  def initialize
16
16
  # get start time
17
- beginning = Time.now
17
+ $beginning = Time.now
18
18
 
19
19
  # Get command line arguments arguments
20
20
  cmd = ARGV[0]
@@ -56,12 +56,12 @@ class Textigniter
56
56
  when "init"
57
57
  Textigniter.init(args)
58
58
  when "scrub"
59
- Textigniter.scrub
59
+ Textigniter.scrub(args)
60
60
  else
61
61
  Textigniter.help(args)
62
62
  end
63
63
  # print out elapsed time
64
- puts "Time elapsed: ".yellow_on_black + "#{Time.now - beginning} seconds".white_on_black
64
+ puts "Time elapsed: ".yellow_on_black + "#{Time.now - $beginning} seconds".white_on_black
65
65
  # pretty up
66
66
  STDOUT.puts "\r\n"
67
67
  end
@@ -85,9 +85,9 @@ class Textigniter
85
85
  end
86
86
 
87
87
  # Initialize a new scrub object
88
- def self.scrub
88
+ def self.scrub(args)
89
89
  # create a new scrub instance
90
- @scrub = Scrub.new
90
+ @scrub = Scrub.new(args)
91
91
  @scrub.scrub
92
92
  end
93
93
 
data/textigniter.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.rubygems_version = '1.9.2'
3
3
 
4
4
  s.name = 'textigniter'
5
- s.version = '0.0.32'
5
+ s.version = '0.0.33'
6
6
  s.executables << 'textigniter'
7
7
  s.date = '2011-11-19'
8
8
 
@@ -43,16 +43,23 @@ Gem::Specification.new do |s|
43
43
  lib/skeleton/.textigniter/layouts/blog.liquid
44
44
  lib/skeleton/.textigniter/layouts/default.liquid
45
45
  lib/skeleton/.textigniter/layouts/partials
46
+ lib/skeleton/plugins/README.textile
46
47
  lib/textigniter.rb
47
48
  lib/textigniter/build.rb
48
49
  lib/textigniter/help.rb
49
50
  lib/textigniter/init.rb
51
+ lib/textigniter/plugins.rb
50
52
  lib/textigniter/scrub.rb
51
53
  lib/textigniter/build/render_files.rb
52
54
  lib/textigniter/build/script_parser.rb
53
55
  lib/textigniter/build/style_parser.rb
54
56
  lib/textigniter/build/template_parser.rb
55
57
  lib/textigniter/build/text_parser.rb
58
+ lib/textigniter/plugins/created_at.rb
59
+ lib/textigniter/plugins/slug.rb
60
+ lib/textigniter/plugins/type.rb
61
+ lib/textigniter/plugins/tags.rb
62
+ lib/textigniter/plugins/twitter.rb
56
63
  ]
57
64
  # = MANIFEST =
58
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textigniter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: RedCloth
16
- requirement: &70139173890900 !ruby/object:Gem::Requirement
16
+ requirement: &70119255384020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70139173890900
24
+ version_requirements: *70119255384020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kramdown
27
- requirement: &70139173890360 !ruby/object:Gem::Requirement
27
+ requirement: &70119255382600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.13.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70139173890360
35
+ version_requirements: *70119255382600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: liquid
38
- requirement: &70139173889860 !ruby/object:Gem::Requirement
38
+ requirement: &70119255380940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.3.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70139173889860
46
+ version_requirements: *70119255380940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: less
49
- requirement: &70139173889320 !ruby/object:Gem::Requirement
49
+ requirement: &70119255380280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70139173889320
57
+ version_requirements: *70119255380280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: coffee-script
60
- requirement: &70139173888720 !ruby/object:Gem::Requirement
60
+ requirement: &70119255379760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.2.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70139173888720
68
+ version_requirements: *70119255379760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: colored
71
- requirement: &70139173887660 !ruby/object:Gem::Requirement
71
+ requirement: &70119255379000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '1.0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70139173887660
79
+ version_requirements: *70119255379000
80
80
  description: ! " Textigniter is a lightweight static site generator based on textile
81
81
  (markdown optional), liquid, less, and coffeescript. There are no plans for textigniter
82
82
  to support other parsers. Keeping it clean yet powerful. \n"
@@ -104,16 +104,23 @@ files:
104
104
  - lib/skeleton/.textigniter/layouts/about.liquid
105
105
  - lib/skeleton/.textigniter/layouts/blog.liquid
106
106
  - lib/skeleton/.textigniter/layouts/default.liquid
107
+ - lib/skeleton/plugins/README.textile
107
108
  - lib/textigniter.rb
108
109
  - lib/textigniter/build.rb
109
110
  - lib/textigniter/help.rb
110
111
  - lib/textigniter/init.rb
112
+ - lib/textigniter/plugins.rb
111
113
  - lib/textigniter/scrub.rb
112
114
  - lib/textigniter/build/render_files.rb
113
115
  - lib/textigniter/build/script_parser.rb
114
116
  - lib/textigniter/build/style_parser.rb
115
117
  - lib/textigniter/build/template_parser.rb
116
118
  - lib/textigniter/build/text_parser.rb
119
+ - lib/textigniter/plugins/created_at.rb
120
+ - lib/textigniter/plugins/slug.rb
121
+ - lib/textigniter/plugins/type.rb
122
+ - lib/textigniter/plugins/tags.rb
123
+ - lib/textigniter/plugins/twitter.rb
117
124
  - LICENSE
118
125
  homepage: http://github.com/kalebheitzman/textigniter
119
126
  licenses: