imedo-css_doc 0.0.3 → 0.0.4

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.
@@ -1,19 +1,5 @@
1
1
  module CSSDoc
2
2
  class DocumentDocumentation < Documentation
3
- attr_accessor :file, :note, :appdef, :link, :copyright, :author, :css_for, :version
4
-
5
- def parse(lines)
6
- section_text = []
7
- lines.each do |line|
8
- unless parse_one_liners(line)
9
- section_text << line
10
- end
11
- end
12
- sections << TextSection.new(section_text)
13
- end
14
-
15
- def one_liners
16
- ['file', 'note', 'appdef', 'link', 'copyright', 'author', 'css-for', 'version']
17
- end
3
+ define_tag :file, :note, :appdef, :link, :copyright, :author, :css_for, :version
18
4
  end
19
5
  end
@@ -36,6 +36,17 @@ module CSSDoc
36
36
  attr_accessor :comment
37
37
  attr_accessor :sections
38
38
 
39
+ def self.tags
40
+ @tags ||= []
41
+ end
42
+
43
+ def self.define_tag(*names)
44
+ names.each do |name|
45
+ attr_accessor name
46
+ tags << name
47
+ end
48
+ end
49
+
39
50
  def initialize(comment)
40
51
  @comment = comment
41
52
  @sections = Sections.new
@@ -46,21 +57,17 @@ module CSSDoc
46
57
  @comment
47
58
  end
48
59
 
49
- def parse_one_liners(line)
50
- one_liners.each do |one_liner|
51
- rx = /@#{one_liner}/
60
+ def parse_tags(line)
61
+ self.class.tags.each do |tag|
62
+ rx = /@#{tag.to_s.gsub('_', '-')}/
52
63
  if line =~ rx
53
- instance_variable_set(:"@#{one_liner.gsub('-', '_')}", line.gsub(rx, "").strip)
64
+ instance_variable_set(:"@#{tag}", line.gsub(rx, "").strip)
54
65
  return true
55
66
  end
56
67
  end
57
68
  return false
58
69
  end
59
70
 
60
- def one_liners
61
- []
62
- end
63
-
64
71
  def parse_comment
65
72
  @parsed_comment ||= comment.gsub(/\*\/$/, '').split("\n").collect { |line| line.gsub(/^\s*\*/, '') }
66
73
  end
@@ -75,7 +82,26 @@ module CSSDoc
75
82
  end
76
83
 
77
84
  def parse(lines)
78
- raise NotImplementedError
85
+ section_type = TextSection
86
+ section_text = []
87
+ lines.each do |line|
88
+ unless parse_tags(line)
89
+ if line =~ /@code/
90
+ sections << section_type.new(section_text)
91
+ section_text = []
92
+ section_type = CodeSection
93
+ elsif line =~ /@endcode/
94
+ sections << section_type.new(section_text)
95
+ section_text = []
96
+ section_type = TextSection
97
+ elsif line =~ /@description/
98
+ section_text << line.gsub(/@description/, '')
99
+ else
100
+ section_text << line
101
+ end
102
+ end
103
+ end
104
+ sections << section_type.new(section_text)
79
105
  end
80
106
  end
81
107
  end
@@ -22,9 +22,8 @@ module CSSDoc
22
22
 
23
23
  FileUtils.mkdir_p("#{@options[:output_dir]}/#{File.dirname(relative_path)}")
24
24
  doc = CSSDoc::Document.parse(File.read(file_name), relative_path)
25
-
26
- html = CSSDoc::DocumentTemplate.new(doc, @options).render
27
- File.open("#{@options[:output_dir]}/#{doc.output_file_name}", 'w') { |file| file.puts html }
25
+
26
+ generate(:template => 'document', :file_name => doc.output_file_name, :locals => { :document => doc, :title => doc.name })
28
27
 
29
28
  @collection.documents << doc
30
29
  end
@@ -32,24 +31,20 @@ module CSSDoc
32
31
 
33
32
  def generate_index_documentation
34
33
  log "Generating Selector Index ..."
35
-
36
- html = CSSDoc::SelectorIndexTemplate.new(@collection, @options).render
37
- File.open("#{@options[:output_dir]}/selector_index.html", 'w') { |file| file.puts html }
34
+
35
+ generate(:template => 'selector_index', :locals => { :collection => @collection, :title => 'Selector Index' })
38
36
 
39
37
  log "Generating File Index ..."
40
38
 
41
- html = CSSDoc::FileIndexTemplate.new(@collection, @options).render
42
- File.open("#{@options[:output_dir]}/file_index.html", 'w') { |file| file.puts html }
39
+ generate(:template => 'file_index', :locals => { :collection => @collection, :title => 'File Index' })
43
40
 
44
41
  log "Generating Section Index ..."
45
42
 
46
- html = CSSDoc::SectionIndexTemplate.new(@collection, @options).render
47
- File.open("#{@options[:output_dir]}/section_index.html", 'w') { |file| file.puts html }
43
+ generate(:template => 'section_index', :locals => { :collection => @collection, :title => 'Section Index' })
48
44
 
49
45
  log "Generating Index Page ..."
50
46
 
51
- html = CSSDoc::IndexTemplate.new(@options).render
52
- File.open("#{@options[:output_dir]}/index.html", 'w') { |file| file.puts html }
47
+ generate(:template => 'index', :locals => { :project_name => @options[:project_name], :title => 'Index' })
53
48
  end
54
49
 
55
50
  def generate_css
@@ -68,5 +63,17 @@ module CSSDoc
68
63
  def log(string)
69
64
  puts string if @options[:verbose]
70
65
  end
66
+
67
+ private
68
+ def generate(params)
69
+ file_name = params[:file_name] || params[:template]
70
+ file_name += '.html' unless file_name =~ /\.html$/
71
+
72
+ relative_root = '.'
73
+ relative_root = (['..'] * File.dirname(file_name).split('/').size).join('/') if file_name =~ /\//
74
+
75
+ html = CSSDoc::Template.new(@options.merge(:relative_root => relative_root)).render(params[:template], params[:locals])
76
+ File.open("#{@options[:output_dir]}/#{file_name}", 'w') { |file| file.puts html }
77
+ end
71
78
  end
72
79
  end
@@ -1,32 +1,5 @@
1
1
  module CSSDoc
2
2
  class RuleSetDocumentation < Documentation
3
- attr_accessor :name, :formerly, :deprecated
4
-
5
- def parse(lines)
6
- section_type = TextSection
7
- section_text = []
8
- lines.each do |line|
9
- unless parse_one_liners(line)
10
- if line =~ /@code/
11
- sections << section_type.new(section_text)
12
- section_text = []
13
- section_type = CodeSection
14
- elsif line =~ /@endcode/
15
- sections << section_type.new(section_text)
16
- section_text = []
17
- section_type = TextSection
18
- elsif line =~ /@description/
19
- section_text << line.gsub(/@description/, '')
20
- else
21
- section_text << line
22
- end
23
- end
24
- end
25
- sections << section_type.new(section_text)
26
- end
27
-
28
- def one_liners
29
- ['name', 'formerly', 'deprecated']
30
- end
3
+ define_tag :name, :formerly, :deprecated
31
4
  end
32
5
  end
@@ -1,19 +1,5 @@
1
1
  module CSSDoc
2
2
  class SectionDocumentation < Documentation
3
- attr_accessor :section
4
-
5
- def parse(lines)
6
- section_text = []
7
- lines.each do |line|
8
- unless parse_one_liners(line)
9
- section_text << line
10
- end
11
- end
12
- sections << TextSection.new(section_text)
13
- end
14
-
15
- def one_liners
16
- ['section']
17
- end
3
+ define_tag :section
18
4
  end
19
5
  end
@@ -7,21 +7,24 @@ module CSSDoc
7
7
  def initialize(options = {})
8
8
  @options = options
9
9
  end
10
-
11
- def render
12
- content = ERB.new(template).result(binding)
13
- ERB.new(layout).result(binding)
14
- end
15
10
 
16
- def title
11
+ class Evaluator
17
12
 
18
13
  end
14
+
15
+ def render(name, variables = {})
16
+ variables.each do |key, value|
17
+ instance_variable_set(:"@#{key}", value)
18
+ end
19
+ content = ERB.new(template(name)).result(binding)
20
+ ERB.new(layout).result(binding)
21
+ end
19
22
 
20
23
  def template_path
21
24
  @options[:template_path] || @@default_template_path
22
25
  end
23
26
 
24
- def template
27
+ def template(template_name)
25
28
  File.read("#{template_path}/#{template_name}.html.erb")
26
29
  end
27
30
 
@@ -30,7 +33,7 @@ module CSSDoc
30
33
  end
31
34
 
32
35
  def relative_root
33
- "."
36
+ @options[:relative_root] || "."
34
37
  end
35
38
 
36
39
  def truncate(string, length)
data/src/css_doc.rb CHANGED
@@ -6,11 +6,6 @@ require File.dirname(__FILE__) + '/css_doc/document_collection'
6
6
  require File.dirname(__FILE__) + '/css_doc/section'
7
7
  require File.dirname(__FILE__) + '/css_doc/rule_set'
8
8
  require File.dirname(__FILE__) + '/css_doc/template'
9
- require File.dirname(__FILE__) + '/css_doc/document_template'
10
- require File.dirname(__FILE__) + '/css_doc/selector_index_template'
11
- require File.dirname(__FILE__) + '/css_doc/file_index_template'
12
- require File.dirname(__FILE__) + '/css_doc/section_index_template'
13
- require File.dirname(__FILE__) + '/css_doc/index_template'
14
9
  require File.dirname(__FILE__) + '/css_doc/documentation'
15
10
  require File.dirname(__FILE__) + '/css_doc/document_documentation'
16
11
  require File.dirname(__FILE__) + '/css_doc/rule_set_documentation'
@@ -5,6 +5,7 @@ module Rake
5
5
  attr_accessor :skip_files
6
6
  attr_accessor :project_name
7
7
  attr_accessor :verbose
8
+ attr_accessor :template_path
8
9
 
9
10
  def initialize(name = :css_doc)
10
11
  @name = name
@@ -21,7 +22,7 @@ module Rake
21
22
  require 'css_doc'
22
23
 
23
24
  driver = CSSDoc::Driver.new
24
- driver.run(:project_name => self.project_name, :input_dir => self.input_dir, :output_dir => self.output_dir, :skip_files => self.skip_files, :verbose => self.verbose)
25
+ driver.run(:project_name => self.project_name, :input_dir => self.input_dir, :output_dir => self.output_dir, :skip_files => self.skip_files, :verbose => self.verbose, :template_path => self.template_path)
25
26
  end
26
27
  end
27
28
  end
@@ -3,7 +3,7 @@
3
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
4
  <head>
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
- <title><%= title %> - CSS Documentation</title>
6
+ <title><%= @title %> - CSS Documentation</title>
7
7
  <link rel="stylesheet" media="all" href="<%= relative_root %>/css_doc.css" />
8
8
  <link rel="stylesheet" media="all" href="<%= relative_root %>/styles.css" />
9
9
  </head>
@@ -3,7 +3,7 @@
3
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
4
  <head>
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
- <title><%= title %> - CSS Documentation</title>
6
+ <title><%= @title %> - CSS Documentation</title>
7
7
  <link rel="stylesheet" media="all" href="<%= relative_root %>/css_doc.css" />
8
8
  <link rel="stylesheet" media="all" href="<%= relative_root %>/styles.css" />
9
9
  </head>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imedo-css_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Kadauke
@@ -27,17 +27,12 @@ files:
27
27
  - src/css_doc/document_collection.rb
28
28
  - src/css_doc/document_documentation.rb
29
29
  - src/css_doc/document_handler.rb
30
- - src/css_doc/document_template.rb
31
30
  - src/css_doc/documentation.rb
32
31
  - src/css_doc/driver.rb
33
- - src/css_doc/file_index_template.rb
34
- - src/css_doc/index_template.rb
35
32
  - src/css_doc/rule_set.rb
36
33
  - src/css_doc/rule_set_documentation.rb
37
34
  - src/css_doc/section.rb
38
35
  - src/css_doc/section_documentation.rb
39
- - src/css_doc/section_index_template.rb
40
- - src/css_doc/selector_index_template.rb
41
36
  - src/css_doc/template.rb
42
37
  - src/css_doc.rb
43
38
  - src/css_pool/visitors/to_css.rb
@@ -1,24 +0,0 @@
1
- module CSSDoc
2
- class DocumentTemplate < Template
3
- def initialize(document, options = {})
4
- super(options)
5
- @document = document
6
- end
7
-
8
- def template_name
9
- 'document'
10
- end
11
-
12
- def title
13
- @document.name
14
- end
15
-
16
- def relative_root
17
- if @document.name =~ /\//
18
- (['..'] * File.dirname(@document.name).split('/').size).join('/')
19
- else
20
- '.'
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- module CSSDoc
2
- class FileIndexTemplate < Template
3
- def initialize(collection, options = {})
4
- super(options)
5
- @collection = collection
6
- end
7
-
8
- def template_name
9
- 'file_index'
10
- end
11
-
12
- def title
13
- "File Index"
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module CSSDoc
2
- class IndexTemplate < Template
3
- def initialize(options)
4
- super
5
- @project_name = options[:project_name]
6
- end
7
-
8
- def template_name
9
- 'index'
10
- end
11
-
12
- def title
13
- "Index"
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module CSSDoc
2
- class SectionIndexTemplate < Template
3
- def initialize(collection, options = {})
4
- super(options)
5
- @collection = collection
6
- end
7
-
8
- def template_name
9
- 'section_index'
10
- end
11
-
12
- def title
13
- "Section Index"
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module CSSDoc
2
- class SelectorIndexTemplate < Template
3
- def initialize(collection, options = {})
4
- super(options)
5
- @collection = collection
6
- end
7
-
8
- def template_name
9
- 'selector_index'
10
- end
11
-
12
- def title
13
- "Selector Index"
14
- end
15
- end
16
- end