wst-parser 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0715e64d017d578d777b7b80499d77d64ad1e20f
4
- data.tar.gz: b7f3baee2c62193ce19f26c016b49cbc9bdec03f
3
+ metadata.gz: 3cbbbd2b5726616c3ffe5376492901fc8e2a506d
4
+ data.tar.gz: c8fc819d3cf227d27615713b17cb377013091924
5
5
  SHA512:
6
- metadata.gz: abaa6f5439914b4f56002a998d00c64010939734cb454903a700a4e999f016f3e44cc36076235cc0f358f9721047a1ce4fdaaed7ad89570a68a7f620e5a2c48f
7
- data.tar.gz: 80720f5770b4d342a8dc1bb46de8189b1239213f7f3d35f9af26564e3ffa6225987f0c8382087011cefbb74406490796b7aa2c8dbae03f60a9a2072659dab563
6
+ metadata.gz: cef16b7d956e0d573c36b3242c9088db545333f3da22e0ce58c57e27b9c1b1def5b546d2de87c04fd2b640c27c507f44ec4a2effbd40b3463d32fef163831f57
7
+ data.tar.gz: e4c524757f2ec4ea009c2f440ae1214ed14524acdf702ff5d4959d704b1c3c6d4ab19966b1d303418dce72180ed48e065e8eb28bbbaacafcbb1f70c24fe5bb05
data/bin/wst-parser CHANGED
@@ -6,11 +6,8 @@ dir = ARGV[0] || Dir.pwd
6
6
 
7
7
  Wst::Configuration.read_config dir, false
8
8
 
9
- puts "Pages:"
10
- Wst::Page.all.each do |page|
11
- puts "\t" + page.content_url
12
- end
13
- puts "Posts:"
14
- Wst::Post.all.each do |post|
15
- puts "\t" + post.content_url
9
+ puts "All contents:"
10
+ contents = Wst::Contents.new
11
+ contents.all(true).each do |content|
12
+ puts " - #{content.content_url}"
16
13
  end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ require 'wst/post'
3
+ require 'wst/page'
4
+
5
+ module Wst
6
+ class Contents
7
+ def initialize
8
+ @all = all_contents
9
+ end
10
+
11
+ # Get all contents
12
+ # @param [Boolean] show_non_publised Get all contents or only published
13
+ # @return [Array<Content>] Contents
14
+ def all(show_non_published)
15
+ return @all if show_non_published
16
+ @all.select { |c| c.published }
17
+ end
18
+
19
+ private
20
+ # Get all contents, publised or not
21
+ # @return [Array<Content>] Contents
22
+ def all_contents
23
+ [Page.all, Post.all].flatten
24
+ end
25
+ end
26
+ end
data/lib/wst/page.rb CHANGED
@@ -10,10 +10,34 @@ module Wst
10
10
  end
11
11
  end
12
12
 
13
+ class XmlPage < HamlContent
14
+ include PageComparison
15
+
16
+ @@matcher = /^(.+\/)*(.*)(\.xml\.haml)$/
17
+
18
+ def initialize file_path
19
+ super file_path
20
+
21
+ m, cats, slug, ext = *file_path.match(@@matcher)
22
+ base_path = File.join(Configuration.config['path'], '_pages') + '/'
23
+ @cats = cats.gsub(base_path, '').chomp('/') if !cats.nil? && cats != base_path
24
+ @slug = slug
25
+ @ext = ext
26
+ end
27
+
28
+ def content_url
29
+ "#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.xml"
30
+ end
31
+
32
+ def self.matcher
33
+ @@matcher
34
+ end
35
+ end
36
+
13
37
  class HamlPage < HamlContent
14
38
  include PageComparison
15
39
 
16
- @@matcher = /^(.+\/)*(.*)(\.[^.]+)$/
40
+ @@matcher = /^(.+\/)*(.*)((?<!\.xml)\.[^.]+)$/
17
41
 
18
42
  def initialize file_path
19
43
  super file_path
@@ -51,16 +75,21 @@ module Wst
51
75
  end
52
76
 
53
77
  class Page
78
+ @@glob_xml = '*.xml.haml'
54
79
  @@glob_md = '*.{md,mkd,markdown}'
55
80
  @@glob_haml = '*.haml'
56
81
 
57
82
  class << self
58
83
  def all
59
- (haml_pages + md_pages).sort
84
+ (xml_pages + haml_pages + md_pages).sort
60
85
  end
61
86
 
62
87
  private
63
88
 
89
+ def xml_pages
90
+ page_files(@@glob_xml, XmlPage.matcher).inject([]) { |pages, file| pages << XmlPage.new(file) }
91
+ end
92
+
64
93
  def haml_pages
65
94
  page_files(@@glob_haml, HamlPage.matcher).inject([]) { |pages, file| pages << HamlPage.new(file) }
66
95
  end
data/lib/wst/parser.rb CHANGED
@@ -3,3 +3,4 @@
3
3
  require 'wst/configuration'
4
4
  require 'wst/page'
5
5
  require 'wst/post'
6
+ require 'wst/contents'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wst-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Brissaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse content of a wst instance
14
14
  email: yves.brissaud@gmail.com
@@ -21,6 +21,7 @@ files:
21
21
  - lib/.editorconfig
22
22
  - lib/wst/configuration.rb
23
23
  - lib/wst/content.rb
24
+ - lib/wst/contents.rb
24
25
  - lib/wst/haml_content.rb
25
26
  - lib/wst/md_content.rb
26
27
  - lib/wst/page.rb