content_directory 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmViMTg4NTkxYTIyNWFlNDA1MDhmYTM1YjQ2MzgxNjFiNWNmODE1Zg==
4
+ YWQyZDYxMDlmMjI1ODg3YjgzM2UyNmRlYjBlY2U5Y2YxYTE0YzZlNw==
5
5
  data.tar.gz: !binary |-
6
- ZmZlMTk2YjE3M2IyZTY1MTVhNjQ2MTI5NDY1OTQyODVmNmNlMDcwOQ==
6
+ ZWNmZjYxOWJjMTUwNGQxYzM1MWVmN2ZkYzA4YjAzOTE5ZmI2Yzc3ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTkyMjIyMzEwNTRkYzg0YjEzMWZlZGYzMWM5MzI3YmMwZmVmOTE2MzExMmFk
10
- NTdmNmIyOTQyZWVmOTViYzRhZTNiOThhOTQ0ODM1ZTNiZjBkN2FhZTg4YzY1
11
- ZjQzZTY5MmMxMGM5NTJjYTk5ZTY4NDMwMDg2N2FiMThhZTMyZTk=
9
+ MWUxYzM2MjBmNGEyZDRhYWFiZGU0ZjMzNmRmNzc2ZmU3MzllODU4NmE0ZmQz
10
+ NDNmZWYxNWE4NWQwODM4YmNhMzY1MDExNGZiMDIwYWI4Yjg2MDk4NWQ2Zjkw
11
+ MTY0YzBhOGQ5NGYwM2Q0MmZjY2Y3N2VhODMzYTBmZDJkNDI0YTI=
12
12
  data.tar.gz: !binary |-
13
- MjhjNDBmNDFmOWZhOTIzODc5ZGQ2YTZlZjBjMTg2NGM2YzViNTI1MmY1M2Ew
14
- MzA5MDZiYmYxZjI5NDAxNWFhMDcxMjBkN2VjOTMxMzhiZjQwODZkMzNlYzhh
15
- YjcwMDY4OGE0NThlODEyOWY5ZTM5YjczNTBhNzE0MTA0M2EwN2U=
13
+ YWExNGRkZGRjM2U1NWQ3MzdjY2E1MGI4MDJjN2Q5MTA3NjEwZjM2Y2M3ZTEy
14
+ OTMwZmQ1ODE5ZThlMDQ3NTZmMTk3ZjFjMTk2NmZkMTFhN2FiNGI1NTc1ZmYz
15
+ NjEwN2FlYTUxODY2M2M1YWVkODRkZTZiY2ZjY2EzYzAxOTVjNDM=
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ - An entry file, which only contains metadata, now returns `text` and `html` as nil
6
+
7
+ ## 0.1.0
8
+
9
+ - Initial release
data/README.md CHANGED
@@ -1,12 +1,73 @@
1
- # ContentDirectory
1
+ # Content Directory
2
2
 
3
- TODO: Write a gem description
3
+ Content Directory is a lightweight replacement of Content Management System. It provides structure for text based content. It comes with a parser, which allows content entries to have metadata and rich formatting.
4
+
5
+ ## Structure
6
+
7
+ Content Directory does not require a database. Instead, it uses file system. An entry is a file written in Markdown syntax. You can group related entries in a folder.
8
+
9
+ - content
10
+ - home
11
+ - main.md
12
+ - features
13
+ - collaboration.md
14
+ - manage.md
15
+ - posts
16
+ - a-new-blog.md
17
+ - sortable-stars.md
18
+
19
+ ## Writing entries
20
+
21
+ Entry uses Markdown syntax, but there is an additional rule that every entry must have a metadata declaration on the top. Metadata declaration block uses YAML syntax.
22
+
23
+ Title: Introduction
24
+ Date: 2013/03/10
25
+ Tags: ["post", "short"]
26
+
27
+ It was a bright cold day in April, and the clocks were striking
28
+ thirteen. Winston Smith, his chin nuzzled into his breast in an
29
+ effort to escape the vile wind, slipped quickly through the
30
+ glass doors of *Victory Mansions*, though not quickly enough to
31
+ prevent a swirl of gritty dust from entering along with him.
32
+
33
+ The hallway smelt of boiled cabbage and old rag mats. At one end
34
+ of it a coloured poster, too large for indoor display, had been
35
+ tacked to the wall. It depicted simply an **enormous** face,
36
+ more than a metre wide: the face of a man of about forty-five,
37
+ with a heavy black moustache and ruggedly handsome features.
38
+
39
+ ## Reading entries
40
+
41
+ Once you have written entries, you can use `ContentDirectory.find` to get the processed entries and render them into views.
42
+
43
+ `ContentDirectory.find` returns a `Hash` of `ContentDirectory::Entry`. It accepts one argument, which is a path relative to `ContentDirectory.root`. If path is not specified, `ContentDirectory.find` will find all possible entries.
44
+
45
+ posts = ContentDirectory.find "posts"
46
+
47
+ You can use metadata to sort posts by date
48
+
49
+ posts = ContentDirectory.find("posts").values
50
+ posts.sort_by! { |post| post.metadata["Date"] }
51
+
52
+ Entry has three important values: `metadata`, `text`, `html`.
53
+
54
+ 1. `metadata` is a `Hash` of parsed metadata block from entry file.
55
+ 2. `text` is a `String` of original entry text.
56
+ 3. `html` is a `String` of the result of original text after processed by Redcarpet Markdown parser.
57
+
58
+ You can you these three values to render entry to a view.
59
+
60
+ for post in posts
61
+ puts post.metadata["Title"]
62
+ puts post.text
63
+ puts post.html
64
+ end
4
65
 
5
66
  ## Installation
6
67
 
7
68
  Add this line to your application's Gemfile:
8
69
 
9
- gem 'content_directory'
70
+ gem "content_directory"
10
71
 
11
72
  And then execute:
12
73
 
@@ -16,9 +77,24 @@ Or install it yourself as:
16
77
 
17
78
  $ gem install content_directory
18
79
 
19
- ## Usage
80
+ ## Configuration
81
+
82
+ ContentDirectory.root is default to `"#{Rails.root}/content"` when used in Rails. If you want to use other directory, you can easily change it in the initializer.
83
+
84
+ ContentDirectory.root = "path/to/content"
85
+
86
+ ## Use with Rails
87
+
88
+ Content Directory is intended to be used in Rails to extract content from view templates. In this fashion, content can be easily reused and queried.
89
+
90
+ 1. Create `content` directory in Rails root path.
91
+ 2. Write entries in this directory.
92
+ 3. Use `ContentDirectory.find` in the controllers.
93
+ 4. Render entry `html` or `text` in the templates.
94
+
95
+ ## Test
20
96
 
21
- TODO: Write usage instructions here
97
+ rake test
22
98
 
23
99
  ## Contributing
24
100
 
@@ -1,16 +1,16 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'content_directory/version'
4
+ require "content_directory/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "content_directory"
8
8
  spec.version = ContentDirectory::VERSION
9
9
  spec.authors = ["Steve Randy Tantra"]
10
10
  spec.email = ["steve.randy@gmail.com"]
11
- spec.description = ""
12
- spec.summary = ""
13
- spec.homepage = ""
11
+ spec.description = "Content Directory is a lightweight replacement of Content Management System. It provides structure for text based content. It comes with a parser, which allows content entries to have metadata and rich formatting."
12
+ spec.summary = "Lightweight replacement of Content Management System"
13
+ spec.homepage = "https://github.com/steverandy/content_directory"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -8,17 +8,17 @@ module ContentDirectory
8
8
  def initialize(path)
9
9
  @path = path
10
10
  @text = File.read "#{ContentDirectory.root}/#{@path}"
11
- @metadata = @text.split("\n\n").first
11
+ @metadata, @text = @text.split("\n\n", 2)
12
12
 
13
13
  begin
14
14
  @metadata = YAML.load @metadata
15
- @text = @text.split("\n\n", 2).last
16
15
  rescue Exception => e
17
16
  @metadata = nil
18
17
  end
19
18
  end
20
19
 
21
20
  def html
21
+ return nil unless @text
22
22
  markdown = Redcarpet::Markdown.new Redcarpet::Render::HTML
23
23
  html = markdown.render @text
24
24
  Redcarpet::Render::SmartyPants.render html
@@ -1,3 +1,3 @@
1
1
  module ContentDirectory
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1 @@
1
+ Title: Empty
@@ -19,7 +19,7 @@ class ContentDirectoryTest < ActiveSupport::TestCase
19
19
  assert_equal 2, content.length
20
20
 
21
21
  home = ContentDirectory.find "home"
22
- assert_equal 2, home.length
22
+ assert_equal 3, home.length
23
23
  assert_equal 2, home["features"].length
24
24
  assert_kind_of ContentDirectory::Entry, home["main"]
25
25
  end
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
  class EntryTest < ActiveSupport::TestCase
4
- test "entry" do
4
+ test "entry with metadata and text" do
5
5
  ContentDirectory.root = File.expand_path("../../support/content", __FILE__)
6
6
  home = ContentDirectory.find "home"
7
7
  main = home["main"]
@@ -11,4 +11,15 @@ class EntryTest < ActiveSupport::TestCase
11
11
  assert_equal "Build software better, together.\n\nPowerful collaboration, review, and code management for open source and private development projects.\n", main.text
12
12
  assert_equal "<p>Build software better, together.</p>\n\n<p>Powerful collaboration, review, and code management for open source and private development projects.</p>\n", main.html
13
13
  end
14
+
15
+ test "entry with metadata and no text" do
16
+ ContentDirectory.root = File.expand_path("../../support/content", __FILE__)
17
+ home = ContentDirectory.find "home"
18
+ empty = home["empty"]
19
+ assert_kind_of ContentDirectory::Entry, empty
20
+ assert_equal "Empty", empty.metadata["Title"]
21
+ puts empty.text
22
+ assert_nil empty.text
23
+ assert_nil empty.html
24
+ end
14
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Randy Tantra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-10 00:00:00.000000000 Z
11
+ date: 2013-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -66,7 +66,9 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ''
69
+ description: Content Directory is a lightweight replacement of Content Management
70
+ System. It provides structure for text based content. It comes with a parser, which
71
+ allows content entries to have metadata and rich formatting.
70
72
  email:
71
73
  - steve.randy@gmail.com
72
74
  executables: []
@@ -74,6 +76,7 @@ extensions: []
74
76
  extra_rdoc_files: []
75
77
  files:
76
78
  - .gitignore
79
+ - CHANGELOG.md
77
80
  - Gemfile
78
81
  - LICENSE.txt
79
82
  - README.md
@@ -82,6 +85,7 @@ files:
82
85
  - lib/content_directory.rb
83
86
  - lib/content_directory/entry.rb
84
87
  - lib/content_directory/version.rb
88
+ - test/support/content/home/empty.md
85
89
  - test/support/content/home/features/collaboration.md
86
90
  - test/support/content/home/features/manage.md
87
91
  - test/support/content/home/main.md
@@ -90,7 +94,7 @@ files:
90
94
  - test/test_helper.rb
91
95
  - test/unit/content_directory_test.rb
92
96
  - test/unit/entry_test.rb
93
- homepage: ''
97
+ homepage: https://github.com/steverandy/content_directory
94
98
  licenses:
95
99
  - MIT
96
100
  metadata: {}
@@ -113,8 +117,9 @@ rubyforge_project:
113
117
  rubygems_version: 2.0.2
114
118
  signing_key:
115
119
  specification_version: 4
116
- summary: ''
120
+ summary: Lightweight replacement of Content Management System
117
121
  test_files:
122
+ - test/support/content/home/empty.md
118
123
  - test/support/content/home/features/collaboration.md
119
124
  - test/support/content/home/features/manage.md
120
125
  - test/support/content/home/main.md