guider 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/guider CHANGED
@@ -10,9 +10,11 @@ require "guider/guide"
10
10
  require "guider/config"
11
11
  require "guider/template"
12
12
  require "guider/index"
13
+ require "guider/inline_tags"
13
14
 
14
15
  options = {
15
16
  :output => Dir.pwd + "/out",
17
+ :link_url => "http://localhost/extjs/",
16
18
  }
17
19
 
18
20
  input_files = OptionParser.new do |opts|
@@ -23,6 +25,10 @@ input_files = OptionParser.new do |opts|
23
25
  options[:output] = dir
24
26
  end
25
27
 
28
+ opts.on("--link-url=URL", "Base path for links created by {@link} tags.") do |url|
29
+ options[:link_url] = url
30
+ end
31
+
26
32
  opts.on("-h", "--help", "Show this help message") do
27
33
  puts opts
28
34
  exit
@@ -40,13 +46,17 @@ Dir[tpl_dir+"/*.{js,css,ico}"].each do |fname|
40
46
  FileUtils.cp(fname, options[:output])
41
47
  end
42
48
 
49
+ # Configure {@link} tags.
50
+ inline_tags = Guider::InlineTags.new
51
+ inline_tags.link_url = options[:link_url]
52
+
43
53
  # Read the template HTML file
44
54
  tpl = Guider::Template.new(tpl_dir + "/guide.html")
45
55
 
46
56
  # The guides.json file
47
57
  config_file = input_files[0]
48
58
 
49
- guides = Guider::Config.new(config_file, tpl).guides
59
+ guides = Guider::Config.new(config_file, tpl, inline_tags).guides
50
60
 
51
61
  guides.each do |guide|
52
62
  guide.write(options[:output])
@@ -59,7 +69,3 @@ html = index_tpl.apply({
59
69
  :title => "Guides",
60
70
  :content => "blah",
61
71
  })
62
-
63
-
64
-
65
-
data/guider.gemspec CHANGED
@@ -2,8 +2,8 @@ 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.1'
6
- s.date = '2013-03-11'
5
+ s.version = '0.0.2'
6
+ s.date = '2013-03-15'
7
7
  s.summary = "Sencha guide generator"
8
8
  s.description = "JSDuck-compatible guides generator"
9
9
  s.homepage = "https://github.com/nene/guider"
data/lib/guider/config.rb CHANGED
@@ -5,11 +5,11 @@ module Guider
5
5
  # Reads the guides config file.
6
6
  # Turns it into list Guide instances accessible through .guides attribute.
7
7
  class Config
8
- def initialize(path, tpl)
8
+ def initialize(path, tpl, inline_tags)
9
9
  guide_cfgs = flatten(JSON.parse(IO.read(path)))
10
10
  guide_cfgs.each {|g| keys_to_symbols(g) }
11
11
  guide_cfgs.each {|g| add_path(g, path) }
12
- @guides = to_guides(guide_cfgs, tpl)
12
+ @guides = to_guides(guide_cfgs, tpl, inline_tags)
13
13
  end
14
14
 
15
15
  # List of Guide instances.
@@ -41,8 +41,8 @@ module Guider
41
41
  end
42
42
 
43
43
  # Turns guide configs to actual Guide instances
44
- def to_guides(guide_cfgs, tpl)
45
- guide_cfgs.find_all {|g| File.exists?(g[:path]) }.map {|g| Guide.new(g, tpl) }
44
+ def to_guides(guide_cfgs, tpl, inline_tags)
45
+ guide_cfgs.find_all {|g| File.exists?(g[:path]) }.map {|g| Guide.new(g, tpl, inline_tags) }
46
46
  end
47
47
 
48
48
  end
data/lib/guider/guide.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require "kramdown"
2
2
  require "fileutils"
3
- require "guider/inline_tags"
4
3
 
5
4
  module Guider
6
5
  class Guide
7
- def initialize(cfg, tpl)
6
+ def initialize(cfg, tpl, inline_tags)
8
7
  @cfg = cfg
9
8
  @template = tpl
9
+ @inline_tags = inline_tags
10
10
  @markdown = IO.read(@cfg[:path]+"/README.md")
11
11
  @html = Kramdown::Document.new(@markdown).to_html
12
12
  end
@@ -19,7 +19,7 @@ module Guider
19
19
  end
20
20
 
21
21
  def write_html(filename)
22
- html = InlineTags.replace(@html)
22
+ html = @inline_tags.replace(@html)
23
23
  html = @template.apply(:content => html, :title => title)
24
24
  File.open(filename, 'w') {|f| f.write(html) }
25
25
  end
@@ -49,10 +49,12 @@ module Guider
49
49
  end
50
50
  end
51
51
 
52
+ # Copies all files and directories in source dir over to
53
+ # destination dir. Skips README.md, which is treated separately.
52
54
  def copy_images(src, dest)
53
- Dir[src+"/**/*.{png,jpg,jpeg,gif}"].each do |img|
54
- if !["icon.png", "icon-lg.png"].include?(File.basename(img))
55
- FileUtils.cp(img, dest+"/"+File.basename(img))
55
+ Dir[src+"/*"].each do |img|
56
+ if !["README.md"].include?(File.basename(img))
57
+ FileUtils.cp_r(img, dest+"/"+File.basename(img))
56
58
  end
57
59
  end
58
60
  end
data/lib/guider/index.rb CHANGED
@@ -1,7 +1,3 @@
1
- require "kramdown"
2
- require "fileutils"
3
- require "guider/inline_tags"
4
-
5
1
  module Guider
6
2
  class Index
7
3
  def initialize(guides, tpl)
@@ -1,12 +1,21 @@
1
1
  module Guider
2
2
  class InlineTags
3
- def self.replace(html)
3
+ # The base URL for links created by {@link} tags.
4
+ attr_accessor :link_url
5
+
6
+ def initialize
7
+ @link_url = ""
8
+ end
9
+
10
+ def replace(html)
4
11
  replace_link!(html)
5
12
  replace_img!(html)
6
13
  html
7
14
  end
8
15
 
9
- def self.replace_link!(html)
16
+ private
17
+
18
+ def replace_link!(html)
10
19
  re = /\{@link\s+([^\s\}]*)(?:\s+([^\}]*))?}/
11
20
  html.gsub!(re) do |m|
12
21
  m =~ re # re-run regex to extract $1 $2 fields
@@ -20,12 +29,12 @@ module Guider
20
29
  apiref = cls
21
30
  end
22
31
 
23
- url = "http://docs.sencha.com/ext-js/4-1/#!/api/" + apiref
32
+ url = @link_url + "#!/api/" + apiref
24
33
  "<a href='#{url}'>#{alt || ref}</a>"
25
34
  end
26
35
  end
27
36
 
28
- def self.replace_img!(html)
37
+ def replace_img!(html)
29
38
  re = /\{@img\s+([^\s\}]*)(?:\s+([^\}]*))?}/
30
39
  html.gsub!(re) do |m|
31
40
  m =~ re # re-run regex to extract $1 $2 fields
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: 1.3.5
87
87
  requirements: []
88
88
  rubyforge_project: guider
89
- rubygems_version: 1.8.23
89
+ rubygems_version: 1.8.24
90
90
  signing_key:
91
91
  specification_version: 3
92
92
  summary: Sencha guide generator