guider 0.0.7 → 0.0.8

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/bin/guider CHANGED
@@ -6,8 +6,9 @@ $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
6
6
  require "rubygems"
7
7
  require "optparse"
8
8
  require "guider/app"
9
+ require "guider/social"
9
10
 
10
- GUIDER_VERSION = '0.0.7'
11
+ GUIDER_VERSION = '0.0.8'
11
12
 
12
13
  def format_footer(text)
13
14
  guider = "<a href='https://github.com/nene/guider'>Guider</a>"
@@ -22,6 +23,9 @@ options = {
22
23
  :link_url => "http://localhost/extjs/",
23
24
  :tpl_dir => File.dirname(File.dirname(__FILE__)) + "/template",
24
25
  :warnings => false,
26
+ :social => [],
27
+ :search => nil,
28
+ :analytics => nil,
25
29
  }
26
30
 
27
31
  input_files = OptionParser.new do |opts|
@@ -52,6 +56,24 @@ input_files = OptionParser.new do |opts|
52
56
  options[:index] = path
53
57
  end
54
58
 
59
+ opts.on("--social=google,twitter,facebook", Array, "Buttons to add to the page.") do |social|
60
+ social = social.map {|t| t.to_sym }
61
+ unsupported = social.find_all {|t| !Guider::Social.supported_types.include?(t) }
62
+ if unsupported.length > 0
63
+ $stderr.puts "ERROR: Unsupported social button type: " + unsupported.join(" ")
64
+ exit(1)
65
+ end
66
+ options[:social] = social
67
+ end
68
+
69
+ opts.on("--search=id", "ID of custom google search engine.") do |id|
70
+ options[:search] = id
71
+ end
72
+
73
+ opts.on("--analytics=id", "ID for Google Analytics tracking.") do |id|
74
+ options[:analytics] = id
75
+ end
76
+
55
77
  opts.on("--warnings", "Enables warnings.") do
56
78
  options[:warnings] = true
57
79
  end
data/guider.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.required_rubygems_version = ">= 1.3.5"
3
3
 
4
4
  s.name = 'guider'
5
- s.version = '0.0.7'
5
+ s.version = '0.0.8'
6
6
  s.date = Time.new.strftime('%Y-%m-%d')
7
7
  s.summary = "Sencha guide generator"
8
8
  s.description = "JSDuck-compatible guides generator"
@@ -0,0 +1,27 @@
1
+ module Guider
2
+ # Generates HTML for Google Analytics.
3
+ class Analytics
4
+ # Given the ID of Google analytics tracker, returns the tracker
5
+ # script. Returns empty string when no ID given.
6
+ def self.to_html(id)
7
+ return "" unless id
8
+
9
+ <<-EOHTML
10
+ <script type="text/javascript">
11
+ var _gaq = _gaq || [];
12
+ _gaq.push(['_setAccount', '#{id}']);
13
+ _gaq.push(['_trackPageview']);
14
+ (function() {
15
+ var ga = document.createElement('script');
16
+ ga.type = 'text/javascript';
17
+ ga.async = true;
18
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +
19
+ '.google-analytics.com/ga.js';
20
+ var s = document.getElementsByTagName('script')[0];
21
+ s.parentNode.insertBefore(ga, s);
22
+ })();
23
+ </script>
24
+ EOHTML
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'guider/template'
2
+ require 'guider/social'
3
+ require 'guider/search'
4
+ require 'guider/analytics'
5
+ require 'guider/prettify'
6
+ require 'guider/font'
7
+
8
+ module Guider
9
+ # Initializes the common Guider template placeholders with default
10
+ # values generated from Guider options.
11
+ class DefaultTemplate < Template
12
+ def initialize(path, options)
13
+ super(path, {
14
+ :title => options[:title],
15
+ :footer => options[:footer],
16
+ :search => Social.to_html(options[:social]),
17
+ :search => Search.to_html(options[:search]),
18
+ :analytics => Analytics.to_html(options[:analytics]),
19
+ :prettify => Prettify.to_html,
20
+ :font => Font.to_html,
21
+ })
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Guider
2
+ # Generates <script> tag for including google font.
3
+ class Font
4
+ def self.to_html
5
+ <<-EOHTML
6
+ <script type="text/javascript">
7
+ (function(){
8
+ var protocol = (document.location.protocol === "https:") ? "https:" : "http:";
9
+ document.write("<link href='"+protocol+"//fonts.googleapis.com/css?family=Exo' rel='stylesheet' type='text/css' />");
10
+ })();
11
+ </script>
12
+ EOHTML
13
+ end
14
+ end
15
+ end
data/lib/guider/guide.rb CHANGED
@@ -20,8 +20,6 @@ module Guider
20
20
  html = @inline_tags.replace(@html)
21
21
  html = @template.apply({
22
22
  :content => html,
23
- :title => @options[:title],
24
- :footer => @options[:footer],
25
23
  :guide_name => guide_name,
26
24
  :path => @rel_path,
27
25
  })
@@ -1,4 +1,4 @@
1
- require "guider/template"
1
+ require "guider/default_template"
2
2
  require "guider/inline_tags"
3
3
  require "guider/guide"
4
4
 
@@ -11,7 +11,7 @@ module Guider
11
11
  @inline_tags.link_url = options[:link_url]
12
12
 
13
13
  # Create guide rendering template
14
- @tpl = Template.new(options[:tpl_dir] + "/guide.html")
14
+ @tpl = DefaultTemplate.new(options[:tpl_dir] + "/guide.html", options)
15
15
 
16
16
  @options = options
17
17
  end
data/lib/guider/index.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'guider/template'
1
+ require 'guider/default_template'
2
2
  require 'guider/config'
3
3
 
4
4
  module Guider
@@ -6,13 +6,11 @@ module Guider
6
6
  def initialize(options)
7
7
  @options = options
8
8
  @config = Config.new(@options[:index])
9
- @tpl = Template.new(@options[:tpl_dir] + "/index.html")
9
+ @tpl = DefaultTemplate.new(@options[:tpl_dir] + "/index.html", @options)
10
10
  end
11
11
 
12
12
  def write
13
13
  html = @tpl.apply({
14
- :title => @options[:title],
15
- :footer => @options[:footer],
16
14
  :content => @config.to_html,
17
15
  })
18
16
  File.open(@options[:output] + "/index.html", 'w') {|f| f.write(html) }
@@ -0,0 +1,19 @@
1
+ module Guider
2
+ # Generates <script> tag for syntax-highlighting code blocks.
3
+ class Prettify
4
+ def self.to_html
5
+ <<-EOHTML
6
+ <script type="text/javascript">
7
+ (function(){
8
+ var pres = document.getElementsByTagName("pre");
9
+ for (var len=pres.length, i=0; i < len; i++) {
10
+ var code = pres[i].getElementsByTagName("code")[0];
11
+ if (code) code.className = "prettyprint";
12
+ }
13
+ prettyPrint();
14
+ })();
15
+ </script>
16
+ EOHTML
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Guider
2
+ # Generates HTML for Google search.
3
+ class Search
4
+ # Given the ID of custom google search engine, returns the script
5
+ # for generating the search box. Returns empty string when no ID
6
+ # given.
7
+ def self.to_html(id)
8
+ return "" unless id
9
+
10
+ <<-EOHTML
11
+ <script>
12
+ (function() {
13
+ var cx = '#{id}';
14
+ var gcse = document.createElement('script');
15
+ gcse.type = 'text/javascript';
16
+ gcse.async = true;
17
+ gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
18
+ '//www.google.com/cse/cse.js?cx=' + cx;
19
+ var s = document.getElementsByTagName('script')[0];
20
+ s.parentNode.insertBefore(gcse, s);
21
+ })();
22
+ </script>
23
+ <gcse:searchbox-only></gcse:searchbox-only>
24
+ EOHTML
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,49 @@
1
+ module Guider
2
+ # Generates HTML for Like-buttons of various social services.
3
+ class Social
4
+ # Given array of social button type names, returns HTML for
5
+ # rendering all these buttons.
6
+ def self.to_html(types)
7
+ types.map {|t| send(t) }.compact.join("\n")
8
+ end
9
+
10
+ # Returns array of supported social button types
11
+ def self.supported_types
12
+ [:google, :twitter, :facebook]
13
+ end
14
+
15
+ def self.google
16
+ <<-EOHTML
17
+ <div class="g-plusone" data-annotation="none"></div>
18
+ <script type="text/javascript">
19
+ (function() {
20
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
21
+ po.src = 'https://apis.google.com/js/plusone.js';
22
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
23
+ })();
24
+ </script>
25
+ EOHTML
26
+ end
27
+
28
+ def self.twitter
29
+ <<-EOHTML
30
+ <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
31
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
32
+ EOHTML
33
+ end
34
+
35
+ def self.facebook
36
+ <<-EOHTML
37
+ <div id="fb-root"></div>
38
+ <script>(function(d, s, id) {
39
+ var js, fjs = d.getElementsByTagName(s)[0];
40
+ if (d.getElementById(id)) return;
41
+ js = d.createElement(s); js.id = id;
42
+ js.src = "//connect.facebook.net/et_EE/all.js#xfbml=1";
43
+ fjs.parentNode.insertBefore(js, fjs);
44
+ }(document, 'script', 'facebook-jssdk'));</script>
45
+ <div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>
46
+ EOHTML
47
+ end
48
+ end
49
+ end
@@ -2,13 +2,19 @@ module Guider
2
2
  # Reads a template from file.
3
3
  # Allows replacing {placeholders} inside it.
4
4
  class Template
5
- def initialize(path)
5
+ # Takes path to the template and an optional defaults hash mapping
6
+ # placeholders to values. These are the default values for
7
+ # placeholders for which no value is given in the hash passed to
8
+ # #apply method.
9
+ def initialize(path, defaults={})
6
10
  @template = IO.read(path)
11
+ @defaults = defaults
7
12
  end
8
13
 
9
14
  # Sets the values for placeholders inside template.
10
15
  # Returns the template text with placeholders replaced.
11
16
  def apply(hash)
17
+ hash = @defaults.merge(hash)
12
18
  @template.gsub(/\{\w+\}/) do |placeholder|
13
19
  placeholder =~ /\{(.*)\}/
14
20
  hash[$1.to_sym]
data/template/guide.html CHANGED
@@ -12,11 +12,14 @@
12
12
 
13
13
  <div id="container">
14
14
  <div id="header">
15
+ <div class="google-search">{search}</div>
15
16
  <h1><a href="{path}">{title}</a></h1>
16
17
  </div>
17
18
 
18
19
  <div id="content">
19
- {content}
20
+ {content}
21
+
22
+ {social}
20
23
  </div>
21
24
  </div>
22
25
 
@@ -24,23 +27,9 @@
24
27
  <p>{footer}</p>
25
28
  </div>
26
29
 
27
- <script type="text/javascript">
28
- (function(){
29
- var protocol = (document.location.protocol === "https:") ? "https:" : "http:";
30
- document.write("<link href='"+protocol+"//fonts.googleapis.com/css?family=Exo' rel='stylesheet' type='text/css' />");
31
- })();
32
- </script>
33
-
34
- <script type="text/javascript">
35
- (function(){
36
- var pres = document.getElementsByTagName("pre");
37
- for (var len=pres.length, i=0; i < len; i++) {
38
- var code = pres[i].getElementsByTagName("code")[0];
39
- if (code) code.className = "prettyprint";
40
- }
41
- prettyPrint();
42
- })();
43
- </script>
30
+ {font}
31
+ {prettify}
32
+ {analytics}
44
33
 
45
34
  </body>
46
35
  </html>
data/template/index.html CHANGED
@@ -5,11 +5,14 @@
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
6
  <link rel="shortcut icon" type="image/ico" href="favicon.ico" />
7
7
  <link rel="stylesheet" type="text/css" href="styles.css" />
8
+ <link rel="stylesheet" type="text/css" href="prettify.css" />
9
+ <script type="text/javascript" src="prettify.js"></script>
8
10
  </head>
9
11
  <body id="index-page">
10
12
 
11
13
  <div id="container">
12
14
  <div id="header">
15
+ <div class="google-search">{search}</div>
13
16
  <h1><a href="{path}">{title}</a></h1>
14
17
  </div>
15
18
 
@@ -22,12 +25,9 @@
22
25
  <p>{footer}</p>
23
26
  </div>
24
27
 
25
- <script type="text/javascript">
26
- (function(){
27
- var protocol = (document.location.protocol === "https:") ? "https:" : "http:";
28
- document.write("<link href='"+protocol+"//fonts.googleapis.com/css?family=Exo' rel='stylesheet' type='text/css' />");
29
- })();
30
- </script>
28
+ {font}
29
+ {prettify}
30
+ {analytics}
31
31
 
32
32
  </body>
33
33
  </html>
data/template/styles.css CHANGED
@@ -54,6 +54,13 @@ img {
54
54
  color: white;
55
55
  }
56
56
 
57
+ #header .google-search {
58
+ position: absolute;
59
+ top: 3px;
60
+ right: 20px;
61
+ width: 250px;
62
+ }
63
+
57
64
  #content {
58
65
  max-width: 900px;
59
66
  margin: 0 auto;
metadata CHANGED
@@ -1,76 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guider
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Rene Saarsoo
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-04-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: kramdown
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 35
29
- segments:
30
- - 0
31
- - 14
32
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.14.2
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: json
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.14.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 1
45
- segments:
46
- - 1
47
- - 7
48
- - 5
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
49
37
  version: 1.7.5
50
38
  type: :runtime
51
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.5
52
46
  description: JSDuck-compatible guides generator
53
47
  email: rene.saarsoo@sencha.com
54
- executables:
48
+ executables:
55
49
  - guider
56
50
  extensions: []
57
-
58
51
  extra_rdoc_files: []
59
-
60
- files:
52
+ files:
61
53
  - .gitignore
62
54
  - COPYING
63
55
  - README.md
64
56
  - Rakefile
65
57
  - bin/guider
66
58
  - guider.gemspec
59
+ - lib/guider/analytics.rb
67
60
  - lib/guider/app.rb
68
61
  - lib/guider/config.rb
62
+ - lib/guider/default_template.rb
63
+ - lib/guider/font.rb
69
64
  - lib/guider/guide.rb
70
65
  - lib/guider/guide_factory.rb
71
66
  - lib/guider/index.rb
72
67
  - lib/guider/inline_tags.rb
73
68
  - lib/guider/logger.rb
69
+ - lib/guider/prettify.rb
70
+ - lib/guider/search.rb
71
+ - lib/guider/social.rb
74
72
  - lib/guider/template.rb
75
73
  - template/favicon.ico
76
74
  - template/guide.html
@@ -81,38 +79,26 @@ files:
81
79
  - template/styles.css
82
80
  homepage: https://github.com/nene/guider
83
81
  licenses: []
84
-
85
82
  post_install_message:
86
83
  rdoc_options: []
87
-
88
- require_paths:
84
+ require_paths:
89
85
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
91
87
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- hash: 3
96
- segments:
97
- - 0
98
- version: "0"
99
- required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
93
  none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 17
105
- segments:
106
- - 1
107
- - 3
108
- - 5
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
109
97
  version: 1.3.5
110
98
  requirements: []
111
-
112
99
  rubyforge_project: guider
113
100
  rubygems_version: 1.8.24
114
101
  signing_key:
115
102
  specification_version: 3
116
103
  summary: Sencha guide generator
117
104
  test_files: []
118
-