blastwolf 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blastwolf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tom Gladhill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Blastwolf
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blastwolf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blastwolf
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/blastwolf ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems" # ruby1.9 doesn't "require" it though
4
+ require 'blastwolf'
5
+
6
+ BlastWolf.new.do_it_all
data/blastwolf.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blastwolf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "blastwolf"
8
+ spec.version = Blastwolf::VERSION
9
+ spec.authors = ["Tom Gladhill"]
10
+ spec.email = ["whoojemaflip@gmail.com"]
11
+ spec.description = "Pattern library documentation"
12
+ spec.summary = "Pattern library documentation"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "liquid", "~> 2.5"
25
+ spec.add_dependency "sass", "~> 3.2"
26
+ spec.add_dependency "pygments.rb", "~> 0.5.2"
27
+ end
@@ -0,0 +1,86 @@
1
+
2
+ # lovingly plagerised from https://raw.github.com/mojombo/jekyll/master/lib/jekyll/tags/highlight.rb
3
+
4
+ module Tags
5
+ class HighlightBlock < Liquid::Block
6
+ include Liquid::StandardFilters
7
+
8
+ # The regular expression syntax checker. Start with the language specifier.
9
+ # Follow that by zero or more space separated options that take one of two
10
+ # forms:
11
+ #
12
+ # 1. name
13
+ # 2. name=value
14
+ SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=\w+)?)*)$/
15
+
16
+ def initialize(tag_name, markup, tokens)
17
+ super
18
+ if markup.strip =~ SYNTAX
19
+ @lang = $1
20
+ @options = {}
21
+ if defined?($2) && $2 != ''
22
+ $2.split.each do |opt|
23
+ key, value = opt.split('=')
24
+ if value.nil?
25
+ if key == 'linenos'
26
+ value = 'inline'
27
+ else
28
+ value = true
29
+ end
30
+ end
31
+ @options[key] = value
32
+ end
33
+ end
34
+ else
35
+ raise SyntaxError.new <<-eos
36
+ Syntax Error in tag 'highlight' while parsing the following markup:
37
+
38
+ #{markup}
39
+
40
+ Valid syntax: highlight <lang> [linenos]
41
+ eos
42
+ end
43
+ end
44
+
45
+ def render(context)
46
+ if true
47
+ render_pygments(context, super)
48
+ else
49
+ render_codehighlighter(context, super)
50
+ end
51
+ end
52
+
53
+ def render_pygments(context, code)
54
+ require 'pygments'
55
+
56
+ @options[:encoding] = 'utf-8'
57
+
58
+ output = add_code_tags(
59
+ Pygments.highlight(code, :lexer => @lang, :options => @options),
60
+ @lang
61
+ )
62
+
63
+ output = context["pygments_prefix"] + output if context["pygments_prefix"]
64
+ output = output + context["pygments_suffix"] if context["pygments_suffix"]
65
+ output
66
+ end
67
+
68
+ def render_codehighlighter(context, code)
69
+ #The div is required because RDiscount blows ass
70
+ <<-HTML
71
+ <div>
72
+ <pre><code class='#{@lang}'>#{h(code).strip}</code></pre>
73
+ </div>
74
+ HTML
75
+ end
76
+
77
+ def add_code_tags(code, lang)
78
+ # Add nested <code> tags to code blocks
79
+ code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
80
+ code = code.sub(/<\/pre>/,"</code></pre>")
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ Liquid::Template.register_tag('highlight', Tags::HighlightBlock)
@@ -0,0 +1,10 @@
1
+ <article>
2
+ <h2><a id='{{ title }}'>{{ title }}</a></h2>
3
+ <section>{{ contents }}</section>
4
+
5
+ <pre>
6
+ {{ contents }}
7
+ </pre>
8
+
9
+ <hr />
10
+ </article>
@@ -0,0 +1,21 @@
1
+ <h1>Pattern Library Index</h1>
2
+ <h2>Contents:</h2>
3
+
4
+ <ul>
5
+ {% for pattern in patterns %}
6
+ <li><a href='#{{ pattern.title }}'>{{ pattern.title }}</a></li>
7
+ {% endfor %}
8
+ </ul>
9
+
10
+ {% for pattern in patterns %}
11
+ <article>
12
+ <h2><a id='{{ pattern.title }}'>{{ pattern.title }}</a></h2>
13
+ <section>{{ pattern.contents }}</section>
14
+
15
+ {% highlight html %}
16
+ {{ pattern.contents }}
17
+ {% endhighlight %}
18
+
19
+ <hr />
20
+ </article>
21
+ {% endfor %}
@@ -0,0 +1,14 @@
1
+ <html>
2
+ <head>
3
+ <title>{{ title }}</title>
4
+ <link rel='stylesheet' href='css/global.css' media='all'>
5
+ <script src='http://code.jquery.com/jquery-1.10.1.min.js'></script>
6
+ <script src='js/patterns.js'></script>
7
+ <style>.highlight {clear:both; margin-top:50px;}</style>
8
+ </head>
9
+ <body>
10
+ <main>
11
+ {{ content }}
12
+ </main>
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ module Blastwolf
2
+ VERSION = "0.1.0"
3
+ end
data/lib/blastwolf.rb ADDED
@@ -0,0 +1,198 @@
1
+ require "blastwolf/version"
2
+
3
+ require 'pathname'
4
+ require 'liquid'
5
+ require 'sass'
6
+ require 'pygments'
7
+ require 'blastwolf/pygments'
8
+
9
+ PROJECT_ROOT = Dir.pwd
10
+
11
+ class BlastWolf
12
+ def initialize( user_config={} )
13
+
14
+ @config = {
15
+ :template_dir => 'blastwolf/templates',
16
+ :default_scss => ['html.syntax', '_colours', '_layout'],
17
+ :build_folder => File.join(PROJECT_ROOT, '_build'),
18
+ :patterns_folder => File.join(PROJECT_ROOT, 'examples')
19
+ }
20
+
21
+ @config.merge!( user_config )
22
+
23
+ setup_build_folders( @config[:build_folder] )
24
+ end
25
+
26
+ def do_it_all
27
+ generate_homepage
28
+ generate_doc_pages
29
+ build_patterns_artifacts
30
+ build_global_scss
31
+ end
32
+
33
+ def copy_markup(src, dest)
34
+ Dir.glob(File.join(src, '*.html')).each do |file|
35
+ FileUtils.cp file, dest
36
+ end
37
+ end
38
+
39
+ def copy_folders( folders, src, dest )
40
+ folders.each do |f|
41
+ FileUtils.cp_r( File.join(src, f), dest )
42
+ end
43
+ end
44
+
45
+ def setup_build_folders( target_folder )
46
+ # FileUtils.rm_r target_folder unless File.directory?( target_folder )
47
+ FileUtils.mkdir(target_folder) unless File.directory?( target_folder )
48
+
49
+ ['css', 'js', 'scss', 'img'].each do |dir|
50
+ subdir = File.join(target_folder, dir)
51
+ FileUtils.mkdir( subdir ) unless File.directory?( subdir )
52
+ end
53
+ end
54
+
55
+ def generate_homepage
56
+ title = "Index of examples"
57
+ patterns = get_patterns
58
+ html = render( 'index', title, patterns )
59
+ write_file( :home, html )
60
+ end
61
+
62
+ def build_patterns_artifacts
63
+ write_file( :scss, build_artifact( :scss ) )
64
+ build_js
65
+ build_image_dir
66
+ end
67
+
68
+ def build_image_dir
69
+ img_dir = File.join(@config[:build_folder], 'img')
70
+ Dir.glob(File.join(examples_path, "*.{jpg,png,gif}")) do |file|
71
+ puts file
72
+ FileUtils.cp file, img_dir
73
+ end
74
+ end
75
+
76
+ def generate_doc_pages
77
+ get_patterns.each do |pattern|
78
+ doc = render( 'doc_page', pattern['title'], pattern )
79
+ filename = File.join(@config[:build_folder], pattern['filename'])
80
+ File.open(filename, "w") { |file| file.write(doc) }
81
+ end
82
+ end
83
+
84
+ def build_artifact( type )
85
+ contents = ''
86
+
87
+ Dir.glob(examples_path type) do |file|
88
+ contents << File.read( file )
89
+ contents << "\n\t/* -------------------------- */\n"
90
+ end
91
+
92
+ contents
93
+ end
94
+
95
+ def build_js
96
+ js = "$(document).ready(function() {\n\n"
97
+ js << build_artifact(:js)
98
+ js << "});"
99
+
100
+ write_file( :js, js )
101
+ end
102
+
103
+ def compile_css
104
+ scss_path = File.join(@config[:build_folder], 'scss')
105
+ file = File.join(scss_path, 'global.scss')
106
+ template = File.read(file)
107
+ sass_engine = Sass::Engine.new(template, { :load_paths => [scss_path], :syntax => :scss,})
108
+ output = sass_engine.render
109
+
110
+ write_file( :css, output )
111
+ end
112
+
113
+ def build_global_scss
114
+ includes = @default_scss
115
+ includes << "patterns"
116
+ file_contents = includes.map { |inc|
117
+ "@import '#{inc}';\n"
118
+ }.join()
119
+
120
+ write_file( :global_scss, file_contents )
121
+ end
122
+
123
+
124
+ def get_patterns
125
+ patterns = []
126
+ Dir.glob(examples_path :html ).each do |file|
127
+ patterns << {
128
+ 'title' => get_title( file ),
129
+ 'filename' => get_filename( file ),
130
+ 'contents' => File.read( file )
131
+ }
132
+ end
133
+ patterns
134
+ end
135
+
136
+ def render( template_file, page_title, vars )
137
+
138
+ contents = Liquid::Template.parse( get_template( template_file ) )
139
+ layout = Liquid::Template.parse( get_template('layout') )
140
+
141
+ vars = { 'patterns' => vars } if vars.kind_of?(Array)
142
+
143
+ rendered_page = layout.render(
144
+ 'title' => page_title,
145
+ 'content' => contents.render( vars )
146
+ )
147
+ end
148
+
149
+ def get_template( filename )
150
+ template_filename = filename + '.liquid'
151
+ template_dir = File.join(File.dirname(__FILE__), 'blastwolf', 'templates')
152
+ File.read(File.join(template_dir, template_filename))
153
+ end
154
+
155
+ def write_file( file_descriptor, contents )
156
+ case file_descriptor
157
+ when :scss
158
+ filename = 'scss/patterns.scss'
159
+ when :js
160
+ filename = 'js/patterns.js'
161
+ when :home
162
+ filename = 'index.html'
163
+ when :global_scss
164
+ filename = 'scss/global.scss'
165
+ when :css
166
+ filename = 'css/global.css'
167
+ else
168
+ raise "I've no idea what file you want me to write"
169
+ end
170
+
171
+ filename = File.join(@config[:build_folder], filename)
172
+ puts filename
173
+
174
+ File.open(filename, 'w') { |file| file.write(contents) }
175
+ end
176
+
177
+
178
+ def get_title( file )
179
+ get_filename( file ).gsub(/\..*$/, '').gsub(/_(.)/) {|s| " #{s.upcase}" }
180
+ end
181
+
182
+
183
+ def get_filename( absolute_file_path )
184
+ Pathname.new( absolute_file_path ).basename.to_s
185
+ end
186
+
187
+
188
+ def examples_path( filetype=nil )
189
+ path = ''
190
+ if [:html, :scss, :js].include? filetype
191
+ path = File.join(PROJECT_ROOT, @config[:patterns_folder], '*', '*.' + filetype.to_s)
192
+ else
193
+ path = File.join(PROJECT_ROOT, @config[:patterns_folder], '*')
194
+ end
195
+ path
196
+ end
197
+
198
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blastwolf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Gladhill
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: liquid
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.5'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sass
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.2'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pygments.rb
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.5.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.5.2
94
+ description: Pattern library documentation
95
+ email:
96
+ - whoojemaflip@gmail.com
97
+ executables:
98
+ - blastwolf
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/blastwolf
108
+ - blastwolf.gemspec
109
+ - lib/blastwolf.rb
110
+ - lib/blastwolf/pygments.rb
111
+ - lib/blastwolf/templates/doc_page.liquid
112
+ - lib/blastwolf/templates/index.liquid
113
+ - lib/blastwolf/templates/layout.liquid
114
+ - lib/blastwolf/version.rb
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Pattern library documentation
140
+ test_files: []