adocsite 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +21 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +82 -0
  5. data/Rakefile +1 -0
  6. data/TODO.md +12 -0
  7. data/adocsite.gemspec +32 -0
  8. data/bin/adocsite +63 -0
  9. data/examples/myconfig.rb +7 -0
  10. data/examples/mywpconfig.rb +9 -0
  11. data/lib/adocsite.rb +35 -0
  12. data/lib/adocsite/commands.rb +83 -0
  13. data/lib/adocsite/config.rb +66 -0
  14. data/lib/adocsite/content_loader.rb +59 -0
  15. data/lib/adocsite/content_types.rb +60 -0
  16. data/lib/adocsite/context.rb +118 -0
  17. data/lib/adocsite/engine.rb +147 -0
  18. data/lib/adocsite/site.rb +49 -0
  19. data/lib/adocsite/templates.rb +91 -0
  20. data/lib/adocsite/version.rb +3 -0
  21. data/lib/adocsite/wp/post.rb +170 -0
  22. data/tpl/default/includes/anything.haml +2 -0
  23. data/tpl/default/includes/bottom.haml +2 -0
  24. data/tpl/default/includes/footer.haml +4 -0
  25. data/tpl/default/includes/header.haml +2 -0
  26. data/tpl/default/includes/menu.haml +9 -0
  27. data/tpl/default/includes/one_level_menu.haml +5 -0
  28. data/tpl/default/includes/top.haml +2 -0
  29. data/tpl/default/layouts/compact.haml +14 -0
  30. data/tpl/default/layouts/default.haml +14 -0
  31. data/tpl/default/literals/google_analytics +7 -0
  32. data/tpl/default/partials/article.haml +2 -0
  33. data/tpl/default/partials/category.haml +6 -0
  34. data/tpl/default/partials/home.haml +12 -0
  35. data/tpl/default/partials/page.haml +2 -0
  36. data/tpl/default/resources/asciidoc.js +189 -0
  37. data/tpl/default/resources/asciidoctor.css +351 -0
  38. data/tpl/default/resources/funky.css +0 -0
  39. data/tpl/default/resources/kernel.css +0 -0
  40. data/tpl/default/resources/myblueraven.css +11 -0
  41. data/tpl/default/resources/myblueraven.js +0 -0
  42. data/tpl/default/resources/old-myblueraven.css +1316 -0
  43. data/tpl/default/resources/sleepy.js +0 -0
  44. metadata +201 -0
data/.gitignore ADDED
@@ -0,0 +1,21 @@
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
18
+ deploy
19
+ work
20
+ .project
21
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adocsite.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,82 @@
1
+ # ADocSite in a few words
2
+
3
+ The idea behind this gem is this:
4
+
5
+ * You have a bunch of text files where you keep your howto's, todo's, brilliant ideas, code snippets, etc. etc.
6
+ * There's just so many of them already, and you are loosing track of what is where
7
+ * You wish you can have a sort of index of them all where you can easily find them and navigate between them.
8
+
9
+ ADocSite takes:
10
+
11
+ * All those text files which are kept somewhere around in bunch of folders with funny names.
12
+ * All the images and other files that you keep with those text documents.
13
+
14
+ and generates one simple static web site out of it.
15
+
16
+ Now you can go, open index.html and browse through all those documents of yours and view them as web pages.
17
+
18
+ # Some more details
19
+
20
+ ADocSite is implemented in [Ruby](https://www.ruby-lang.org/en/). It expects that all files with content are
21
+ written as [asciidoc](http://www.methods.co.nz/asciidoc/) text files. These files are converted into HTML using [asciidoctor](http://asciidoctor.org/).
22
+
23
+ All documents are considered to be **articles** unless they are explicitly marked to be **pages**.
24
+ Articles can be grouped into **categories**, pages are entities for them selves. That's the only difference
25
+ between the two.
26
+
27
+ Usually, asciidoctor generates one complete HTML page from one text file, head, body and all. ADocSite uses
28
+ asciidoctor to render text file content as a HTML section, without html, head and body tags. This _partial_ HTML
29
+ text is then inserted into final HTML page at it's predeterminad place.
30
+
31
+ You can already tell: how final HTML pages look is determined by **templates**. ADocSite uses [HAML](http://haml.info/)
32
+ templates so its final output can take any shape and form you wish it to take.
33
+
34
+ So, there you have it:
35
+
36
+ ADocSite generates static web site.
37
+
38
+ All content consists of **asciidoc formatted text files**.
39
+
40
+ There are **articles**, organized into **categories**, and **pages**.
41
+
42
+ Final shape of everything is controlled by haml **templates**.
43
+
44
+ ADocSite **is** very simple to use and to play with. Don't let the _"asciidoc formatted text file"_ thing
45
+ scare you. You only need to know three things as a necessarry minimum to write asciidoc files:
46
+
47
+ * how to write a document title
48
+ * how to write a list of categories that the article belongs to
49
+ * how to type on a keyboard
50
+
51
+ That's it.
52
+
53
+ Really.
54
+
55
+ [Here, let me show you...](http://myblueraven.com/adocsite).
56
+
57
+
58
+ ## Installation
59
+
60
+ Add this line to your application's Gemfile:
61
+
62
+ gem 'adocsite'
63
+
64
+ And then execute:
65
+
66
+ $ bundle
67
+
68
+ Or install it yourself as:
69
+
70
+ $ gem install adocsite
71
+
72
+ ## Usage
73
+
74
+ TODO: Write usage instructions here
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( http://github.com/<my-github-username>/adocsite/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/TODO.md ADDED
@@ -0,0 +1,12 @@
1
+ # Adocsite
2
+
3
+ Bugz
4
+
5
+ * [ ] when posting article, if code crashes after initial post, article draft is left at the Wordpress server.
6
+ * [ ] different posts that link to same image create multiple media library entries for that same image.
7
+
8
+
9
+ Just a list of things worth looking into.
10
+
11
+ * [ ] should engine be reusable or should it be created new for each theme/layout combination?
12
+
data/adocsite.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adocsite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "adocsite"
8
+ spec.version = Adocsite::VERSION
9
+ spec.authors = ["Bruce Brennan"]
10
+ spec.email = ["bb@myblueraven.com"]
11
+ spec.summary = %q{Static site generator.}
12
+ spec.description = %q{Very simple static site generator for asciidoc documents.}
13
+ spec.homepage = "http://myblueraven.com/adocsite"
14
+ spec.license = "GPL v3"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'haml'
22
+ spec.add_dependency 'asciidoctor'
23
+ spec.add_dependency 'tilt'
24
+ spec.add_dependency 'commander'
25
+ spec.add_dependency 'rubypress'
26
+ spec.add_dependency 'nokogiri'
27
+ spec.add_dependency 'terminal-table'
28
+ spec.add_dependency 'mime-types'
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.5"
31
+ spec.add_development_dependency "rake"
32
+ end
data/bin/adocsite ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+
6
+ require 'bundler/setup'
7
+ require 'adocsite'
8
+
9
+
10
+ program :version, '1.0.0'
11
+ program :description, 'Very simple static site generator for asciidoc documents'
12
+
13
+ default_command :build
14
+
15
+ command :build do |c|
16
+ c.syntax = 'adocsite build [options]'
17
+ c.summary = ''
18
+ c.description = 'Creates static web site from your asciidoc documents'
19
+ c.example 'Build using default layout', 'adocsite build'
20
+ c.example 'Build using some other layout', 'adocsite build --layout compact'
21
+ c.option '--layout STRING', String, 'Specify layout to use for the theme'
22
+ c.option '--config STRING', String, 'Specify configuration file to use for build'
23
+ c.action do |args, options|
24
+ options.default :layout => 'default'
25
+
26
+ Adocsite::Commands::build args, options
27
+ end
28
+ end
29
+
30
+ command :dump do |c|
31
+ c.syntax = 'adocsite dump'
32
+ c.summary = ''
33
+ c.description = 'Dumps default configuration, example custom config file and folder with default templates'
34
+ c.example 'Dump templates and configuration', 'adocsite dump'
35
+ c.action do |args, options|
36
+ Adocsite::Commands::dump args, options
37
+ end
38
+ end
39
+
40
+ command :post do |c|
41
+ c.syntax = 'adocsite post [--config config_file] article_name | --title "article title"'
42
+ c.summary = ''
43
+ c.description = 'Post article to a Wordpress blog'
44
+ c.example 'Post an article by it\'s key name', 'adocsite post my_article_for_blog'
45
+ c.example 'Post an article by it\'s title', 'adocsite post --title "My article for blog"'
46
+ c.option '--title STRING', String, 'Specify article to post by it\'s title'
47
+ c.option '--config STRING', String, 'Specify configuration file to use for posting article'
48
+ c.action do |args, options|
49
+ Adocsite::Commands::post args, options
50
+ end
51
+ end
52
+
53
+ command :list do |c|
54
+ c.syntax = 'adocsite list [--config config_file]'
55
+ c.summary = ''
56
+ c.description = 'List all available articles'
57
+ c.example 'List all available articles', 'adocsite post --list'
58
+ c.option '--config STRING', String, 'Specify configuration file to use for posting article'
59
+ c.action do |args, options|
60
+ Adocsite::Commands::list args, options
61
+ end
62
+ end
63
+
@@ -0,0 +1,7 @@
1
+ # Example custom configuration for Adocsite
2
+
3
+ Adocsite::config = {
4
+ :SITE_TITLE => "Title of My Site",
5
+ :SITE_URL => "http://www.example.com/",
6
+ :INPUT_FOLDERS => ["mysite", "docs"],
7
+ }
@@ -0,0 +1,9 @@
1
+ # Example custom configuration for Adocsite Wordpress posting
2
+
3
+ Adocsite::wpconfig = {
4
+ :host => 'http://www.example.com',
5
+ :path => "/xmlrpc.php",
6
+ :port => 80,
7
+ :username => "editor",
8
+ :password => "editor"
9
+ }
data/lib/adocsite.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "adocsite/version"
2
+
3
+ module Adocsite
4
+ #
5
+ end
6
+
7
+ # built-in
8
+ require 'csv'
9
+ require 'fileutils'
10
+ require 'uri'
11
+
12
+ # required for gems
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ # gems
17
+ require 'haml'
18
+ require 'asciidoctor'
19
+ require 'tilt'
20
+ require 'nokogiri'
21
+ require 'terminal-table'
22
+ require 'rubypress'
23
+ require 'mime/types'
24
+
25
+ # adocsite
26
+ require 'adocsite/content_loader'
27
+ require 'adocsite/content_types'
28
+ require 'adocsite/context'
29
+ require 'adocsite/engine'
30
+ require 'adocsite/site'
31
+ require 'adocsite/templates'
32
+ require 'adocsite/commands'
33
+ require 'adocsite/config'
34
+
35
+ require 'adocsite/wp/post'
@@ -0,0 +1,83 @@
1
+ module Adocsite
2
+ class Commands
3
+ def Commands.build(args, options)
4
+ user_config_file_name = options.config || "adocsite_config.rb"
5
+ user_config_file = File.join(Dir.pwd, user_config_file_name)
6
+ if File.exists?(user_config_file)
7
+ require user_config_file
8
+ end
9
+
10
+ engine = Adocsite::Engine.new
11
+ engine.build(options.layout)
12
+ end
13
+
14
+ def Commands.dump(args, options)
15
+ # default template
16
+ FileUtils.cp_r(Adocsite.config[:TEMPLATES_FOLDER], "adocsite_default_template")
17
+
18
+ # default configuration
19
+ conf = <<-EOS
20
+ # Default configuration for Adocsite
21
+
22
+ Adocsite::config = #{Adocsite.config.pretty_inspect}
23
+
24
+ EOS
25
+ File.open("adocsite_default_config.rb", 'w') {|f| f.write(conf) }
26
+
27
+ # example of custom configuration file
28
+ sample_custom_config = File.join(File.dirname(__FILE__), "..", "..", "examples", "myconfig.rb")
29
+ FileUtils.cp(sample_custom_config, "adocsite_custom_config_sample.rb")
30
+
31
+ # example of custom wp configuration file
32
+ sample_custom_config = File.join(File.dirname(__FILE__), "..", "..", "examples", "mywpconfig.rb")
33
+ FileUtils.cp(sample_custom_config, "adocsite_wp_config_sample.rb")
34
+ end
35
+
36
+ def Commands.post(args, options)
37
+ user_config_file_name = options.config || "adocsite_wp_config.rb"
38
+ user_config_file = File.join(Dir.pwd, user_config_file_name)
39
+ if File.exists?(user_config_file)
40
+ require user_config_file
41
+ end
42
+
43
+ wp = Adocsite::WpPost.new
44
+
45
+ if options.list
46
+ alist = wp.list_articles
47
+ atable = []
48
+ alist.each_pair {|key, value|
49
+ atable << [key.to_str, value]
50
+ }
51
+ puts Terminal::Table.new :headings => ['name', 'title'], :rows => atable
52
+ elsif options.title
53
+ wp.process_by_title(options.title)
54
+ else
55
+ article_name = args.shift || abort('Article title is required.')
56
+ wp.process(article_name)
57
+ end
58
+
59
+ puts 'Done.'
60
+ end
61
+
62
+ def Commands.list(args, options)
63
+ user_config_file_name = options.config || "adocsite_config.rb"
64
+ user_config_file = File.join(Dir.pwd, user_config_file_name)
65
+ if File.exists?(user_config_file)
66
+ require user_config_file
67
+ end
68
+
69
+ alist = Hash.new
70
+ engine = Adocsite::Engine.new
71
+ engine.content_loader.articles.collect{|key, article| alist[key] = article.title}
72
+
73
+ atable = []
74
+ alist.each_pair {|key, value|
75
+ atable << [key.to_str, value]
76
+ }
77
+ puts Terminal::Table.new :headings => ['name', 'title'], :rows => atable
78
+
79
+ puts 'Done.'
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,66 @@
1
+ module Adocsite
2
+ ##################################
3
+ # AdocSite configuration
4
+ #
5
+
6
+ def config
7
+ @settings || Adocsite::DefaultSettings
8
+ end
9
+
10
+ def config= value
11
+ @settings = self.config.merge(value)
12
+ end
13
+
14
+ DefaultSettings = {
15
+ # general stuff
16
+ :SITE_TITLE => "Site Title",
17
+ # if you really want you can put site url here
18
+ # but then you will not be able to browse site by
19
+ # opening index.html file from file explorer
20
+ :SITE_URL => "",
21
+
22
+ # input locations
23
+ :INPUT_FOLDERS => ["work", "docs"],
24
+ :TEMPLATES_FOLDER => File.join(File.dirname(__FILE__), "..", "..", "tpl"),
25
+
26
+ # output locations
27
+ :OUTPUT_FOLDER => "deploy",
28
+ :STYLES_FOLDER => "css",
29
+ :SCRIPTS_FOLDER => "js",
30
+ :IMAGES_FOLDER => "img",
31
+
32
+ # templates
33
+ :THEME => "default",
34
+
35
+ # file filters
36
+ :STYLES => ".css",
37
+ :SCRIPTS => ".js",
38
+ # constant (or variable) defined like this can be passed to method that accepts multiple arguments using *
39
+ # i.e. String.ends_with?(*IMAGES)
40
+ :IMAGES => [".jpg", ".jpeg", ".gif", ".png", ".tif", ".bmp", ".svg"],
41
+ :DOCUMENTS => ".adoc",
42
+ :TEMPLATES => ".haml",
43
+ }
44
+
45
+ ##################################
46
+ # Posting articles to Wordpress
47
+ #
48
+
49
+ def wpconfig
50
+ @wpsettings || Adocsite::DefaultWpSettings
51
+ end
52
+
53
+ def wpconfig= value
54
+ @wpsettings = self.wpconfig.merge(value)
55
+ end
56
+
57
+ DefaultWpSettings = {
58
+ :host => "localhost",
59
+ :path => "/xmlrpc.php",
60
+ :port => 80,
61
+ :username => "editor",
62
+ :password => "editor"
63
+ }
64
+
65
+ module_function :config, :config=, :wpconfig, :wpconfig=
66
+ end