api_guides 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.
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Document do
4
+ describe ".from_xml" do
5
+ let(:xml) do
6
+ %Q{
7
+ <document>
8
+ <title>Foo</title>
9
+ <position>1</position>
10
+ <section title="Bar">
11
+ <docs>Docs</docs>
12
+ <reference title="Baz">Reference content</reference>
13
+ <examples>
14
+ <example language="ruby">ruby examples</example>
15
+ <example language="python">python examples</example>
16
+ </examples>
17
+ </section>
18
+ </document>
19
+ }
20
+ end
21
+
22
+ let(:section) { double('Section') }
23
+
24
+ before(:each) do
25
+ ApiGuides::Section.should_receive(:from_xml).and_return(section)
26
+ end
27
+
28
+ subject { ApiGuides::Document.from_xml(xml) }
29
+
30
+ its(:title) { should == 'Foo' }
31
+
32
+ its(:position) { should == 1 }
33
+
34
+ its(:sections) { should == [section] }
35
+ end
36
+
37
+ describe "#initialize" do
38
+ it "should set the position if given" do
39
+ document = ApiGuides::Document.new :position => 1
40
+ document.position.should == 1
41
+ end
42
+
43
+ it "should set the title if given" do
44
+ document = ApiGuides::Document.new :title => 'Foo'
45
+ document.title.should == 'Foo'
46
+ end
47
+
48
+ it "should set the sections if given" do
49
+ document = ApiGuides::Document.new :sections => []
50
+ document.sections.should == []
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Example do
4
+ describe ".from_xml" do
5
+ let(:xml) { %Q{<example language="ruby">bar</example>} }
6
+
7
+ subject { ApiGuides::Example.from_xml(xml) }
8
+
9
+ its(:language) { should == 'ruby' }
10
+
11
+ its(:content) { should == 'bar' }
12
+ end
13
+
14
+ describe "#initialize" do
15
+ it "should set the language if given" do
16
+ example = ApiGuides::Example.new :language => 'Foo'
17
+ example.language.should == 'Foo'
18
+ end
19
+
20
+ it "should set the content if given" do
21
+ example = ApiGuides::Example.new :content => 'Foo'
22
+ example.content.should == 'Foo'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Generator do
4
+ before(:each) do
5
+ File.open RSpec.support_path.join("test_guide.xml"), "w" do |file|
6
+ file.puts %Q{
7
+ <document>
8
+ <title>Using ApiGuides</title>
9
+ <position>1</position>
10
+ <section title="The Generator">
11
+ <docs>Docs</docs>
12
+ <reference title="Method Signature">Foobar</reference>
13
+ <examples>
14
+ <example language="ruby">ruby examples</example>
15
+ <example language="python">python examples</example>
16
+ </examples>
17
+ </section>
18
+ </document>
19
+ }
20
+ end
21
+ end
22
+
23
+ before(:each) do
24
+ ApiGuides::Generator.new({
25
+ :site_path => RSpec.tmp_path,
26
+ :source_path => RSpec.support_path,
27
+ :title => 'Test Guides',
28
+ :default => 'ruby'
29
+ }).generate
30
+ end
31
+
32
+ it "should generate a ruby file" do
33
+ File.exists?(RSpec.tmp_path.join("ruby.html")).should be_true
34
+ end
35
+
36
+ it "should generate a python file" do
37
+ File.exists?(RSpec.tmp_path.join("python.html")).should be_true
38
+ end
39
+
40
+ it "should copy over the main css" do
41
+ File.exists?(RSpec.tmp_path.join("style.css")).should be_true
42
+ end
43
+
44
+ it "should copy over the syntax css" do
45
+ File.exists?(RSpec.tmp_path.join("syntax.css")).should be_true
46
+ end
47
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ class StringAligner
4
+ include ApiGuides::MarkdownHelper
5
+ end
6
+
7
+ describe StringAligner do
8
+ let(:indented_string) do
9
+ %Q{
10
+ # This String is intended in the source
11
+
12
+ Its lines are underneath it.
13
+
14
+ It may have some code too like this:
15
+
16
+ def this_method(arg)
17
+ puts arg
18
+ end
19
+
20
+ There may also be intended lists!
21
+
22
+ * Value
23
+ * Value
24
+ * Value
25
+
26
+ This should shift it all to the left and align
27
+ all lines with the leading line
28
+ }
29
+ end
30
+
31
+ let(:aligned_string) do
32
+ %Q{
33
+ # This String is intended in the source
34
+
35
+ Its lines are underneath it.
36
+
37
+ It may have some code too like this:
38
+
39
+ def this_method(arg)
40
+ puts arg
41
+ end
42
+
43
+ There may also be intended lists!
44
+
45
+ * Value
46
+ * Value
47
+ * Value
48
+
49
+ This should shift it all to the left and align
50
+ all lines with the leading line
51
+ }
52
+ end
53
+
54
+ it "should align the string" do
55
+ subject.left_align(indented_string).should == aligned_string
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Reference do
4
+ describe ".from_xml" do
5
+ let(:xml) { %Q{<reference title="Foo">bar</reference>} }
6
+
7
+ subject { ApiGuides::Reference.from_xml(xml) }
8
+
9
+ its(:title) { should == 'Foo' }
10
+
11
+ its(:content) { should == 'bar' }
12
+ end
13
+
14
+ describe "#initialize" do
15
+ it "should set the title if given" do
16
+ reference = ApiGuides::Reference.new :title => 'Foo'
17
+ reference.title.should == 'Foo'
18
+ end
19
+
20
+ it "should set the content if given" do
21
+ reference = ApiGuides::Reference.new :content => 'Foo'
22
+ reference.content.should == 'Foo'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Section do
4
+ describe ".from_xml" do
5
+ let(:xml) do
6
+ %Q{
7
+ <section title="Foo">
8
+ <docs>docs</docs>
9
+ <reference title="Bar">
10
+ <![CDATA[
11
+ Insert your markdown here
12
+ ]]>
13
+ </reference>
14
+ <examples>
15
+ <example language="ruby">
16
+ <![CDATA[
17
+ Insert your markdown here>
18
+ ]]>
19
+ </example>
20
+ </example>
21
+ </section>
22
+ }
23
+ end
24
+
25
+ let(:example) { double('Example') }
26
+ let(:reference) { double('Reference') }
27
+
28
+ before(:each) do
29
+ ApiGuides::Example.should_receive(:from_xml).and_return(example)
30
+ ApiGuides::Reference.should_receive(:from_xml).and_return(reference)
31
+ end
32
+
33
+ subject { ApiGuides::Section.from_xml(xml) }
34
+
35
+ its(:title) { should == 'Foo' }
36
+
37
+ its(:docs) { should == 'docs' }
38
+
39
+ its(:examples) { should == [example] }
40
+
41
+ its(:reference) { should == reference }
42
+ end
43
+
44
+ describe "#initialize" do
45
+ it "should set the title if given" do
46
+ section = ApiGuides::Section.new :title => 'Foo'
47
+ section.title.should == 'Foo'
48
+ end
49
+
50
+ it "should set the docs if given" do
51
+ section = ApiGuides::Section.new :docs => 'Foo'
52
+ section.docs.should == 'Foo'
53
+ end
54
+
55
+ it "should set the reference if given" do
56
+ section = ApiGuides::Section.new :reference => 'reference'
57
+ section.reference.should == 'reference'
58
+ end
59
+
60
+ it "should set the examples if given" do
61
+ section = ApiGuides::Section.new :examples => []
62
+ section.examples.should == []
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Views::Document do
4
+ include ApiGuides::MarkdownHelper
5
+
6
+ let(:document) { double('Document', :title => 'A Title', :sections => []) }
7
+
8
+ subject { described_class.new document }
9
+
10
+ its(:title) { should == document.title }
11
+
12
+ its(:id) { should == 'd-a-title' }
13
+
14
+ its(:sections) { should be_a(Array) }
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Views::Example do
4
+ include ApiGuides::MarkdownHelper
5
+
6
+ let(:example) { double('Example', :content => 'content') }
7
+
8
+ subject { described_class.new example }
9
+
10
+ its(:content) { should == markdown(example.content) }
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Views::Reference do
4
+ include ApiGuides::MarkdownHelper
5
+
6
+ let(:reference) { double('Reference', :title => 'A Title', :content => 'content') }
7
+
8
+ subject { described_class.new reference }
9
+
10
+ its(:title) { should == reference.title }
11
+
12
+ its(:id) { should == 'r-a-title' }
13
+
14
+ its(:content) { should == markdown(reference.content) }
15
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiGuides::Views::Section do
4
+ include ApiGuides::MarkdownHelper
5
+
6
+ let(:reference) { double('Reference') }
7
+ let(:example) { double('Example') }
8
+
9
+ let(:section) do
10
+ double('Section',
11
+ :title => 'A Title',
12
+ :docs => 'content',
13
+ :reference => reference,
14
+ :examples => [example])
15
+ end
16
+
17
+ subject { described_class.new section}
18
+
19
+ its(:title) { should == section.title }
20
+
21
+ its(:id) { should == 's-a-title' }
22
+
23
+ its(:docs) { should == markdown(section.docs) }
24
+
25
+ it "should be able to handle empty docs" do
26
+ view = described_class.new double('Section', :docs => nil)
27
+ view.docs.should be_nil
28
+ end
29
+
30
+ its(:reference) { should be_a(ApiGuides::Views::Reference) }
31
+
32
+ its(:examples) { should be_a(Array) }
33
+ end
@@ -0,0 +1,36 @@
1
+ $: << File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'api_guides'
7
+ require 'pathname'
8
+
9
+ module RSpec
10
+ def self.support_path
11
+ Pathname.new "#{File.dirname(__FILE__)}/support"
12
+ end
13
+
14
+ def self.tmp_path
15
+ Pathname.new "#{File.dirname(__FILE__)}/tmp"
16
+ end
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ # == Mock Framework
21
+ #
22
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
23
+ #
24
+ # config.mock_with :mocha
25
+ # config.mock_with :flexmock
26
+ # config.mock_with :rr
27
+ config.mock_with :rspec
28
+
29
+ config.fail_fast = true
30
+
31
+ config.before :each do
32
+ FileUtils.rm_rf RSpec.support_path.join("*")
33
+ FileUtils.rm_rf RSpec.tmp_path.join("*")
34
+ end
35
+ end
36
+
@@ -0,0 +1,14 @@
1
+
2
+ <document>
3
+ <title>Using ApiGuides</title>
4
+ <position>1</position>
5
+ <section title="The Generator">
6
+ <docs>Docs</docs>
7
+ <reference title="Method Signature">Foobar</reference>
8
+ <examples>
9
+ <example language="ruby">ruby examples</example>
10
+ <example language="python">python examples</example>
11
+ </examples>
12
+ </section>
13
+ </document>
14
+
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_guides
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Hawkins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mustache
16
+ requirement: &70144284744740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70144284744740
25
+ - !ruby/object:Gem::Dependency
26
+ name: redcarpet
27
+ requirement: &70144284744220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70144284744220
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ requirement: &70144284743800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70144284743800
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &70144284743260 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70144284743260
58
+ - !ruby/object:Gem::Dependency
59
+ name: i18n
60
+ requirement: &70144284742840 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70144284742840
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70144284742380 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70144284742380
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70144284741960 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70144284741960
91
+ - !ruby/object:Gem::Dependency
92
+ name: simplecov
93
+ requirement: &70144284741540 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70144284741540
102
+ description: Generate HTML documentation for your program with markdown and examples
103
+ for different languages.
104
+ email:
105
+ - me@broadcastingadam.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - Rakefile
113
+ - api_guides.gemspec
114
+ - lib/api_guides.rb
115
+ - lib/api_guides/document.rb
116
+ - lib/api_guides/example.rb
117
+ - lib/api_guides/generator.rb
118
+ - lib/api_guides/markdown_helper.rb
119
+ - lib/api_guides/reference.rb
120
+ - lib/api_guides/resources/style.css
121
+ - lib/api_guides/resources/syntax.css
122
+ - lib/api_guides/section.rb
123
+ - lib/api_guides/templates/page.mustache
124
+ - lib/api_guides/version.rb
125
+ - lib/api_guides/view_helper.rb
126
+ - lib/api_guides/views/document.rb
127
+ - lib/api_guides/views/example.rb
128
+ - lib/api_guides/views/page.rb
129
+ - lib/api_guides/views/reference.rb
130
+ - lib/api_guides/views/section.rb
131
+ - readme.md
132
+ - spec/lib/document_spec.rb
133
+ - spec/lib/example_spec.rb
134
+ - spec/lib/generator_spec.rb
135
+ - spec/lib/markdown_helper_spec.rb
136
+ - spec/lib/reference_spec.rb
137
+ - spec/lib/section_spec.rb
138
+ - spec/lib/views/document_spec.rb
139
+ - spec/lib/views/example_spec.rb
140
+ - spec/lib/views/reference_spec.rb
141
+ - spec/lib/views/section_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/support/test_guide.xml
144
+ homepage: https://github.com/threadedlabs/api_guides
145
+ licenses: []
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 1.8.11
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: ''
168
+ test_files:
169
+ - spec/lib/document_spec.rb
170
+ - spec/lib/example_spec.rb
171
+ - spec/lib/generator_spec.rb
172
+ - spec/lib/markdown_helper_spec.rb
173
+ - spec/lib/reference_spec.rb
174
+ - spec/lib/section_spec.rb
175
+ - spec/lib/views/document_spec.rb
176
+ - spec/lib/views/example_spec.rb
177
+ - spec/lib/views/reference_spec.rb
178
+ - spec/lib/views/section_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/support/test_guide.xml