village 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/Gemfile +29 -0
  2. data/Guardfile +9 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +255 -0
  5. data/Rakefile +29 -0
  6. data/app/controllers/village/articles_controller.rb +27 -0
  7. data/app/controllers/village/pages_controller.rb +16 -0
  8. data/app/views/layouts/village.html.haml +22 -0
  9. data/app/views/village/articles/_addthis.html.haml +8 -0
  10. data/app/views/village/articles/_analytics.html.haml +13 -0
  11. data/app/views/village/articles/_article.html.haml +25 -0
  12. data/app/views/village/articles/_comments.html.haml +8 -0
  13. data/app/views/village/articles/_feed_link.html.haml +2 -0
  14. data/app/views/village/articles/_sidebar.html.haml +13 -0
  15. data/app/views/village/articles/index.atom.builder +26 -0
  16. data/app/views/village/articles/index.html.haml +11 -0
  17. data/app/views/village/articles/index.rss.builder +31 -0
  18. data/app/views/village/articles/show.html.haml +9 -0
  19. data/app/views/village/pages/show.html.haml +1 -0
  20. data/lib/generators/base.rb +178 -0
  21. data/lib/generators/village/articles/USAGE +6 -0
  22. data/lib/generators/village/articles/articles_generator.rb +50 -0
  23. data/lib/generators/village/setup/USAGE +5 -0
  24. data/lib/generators/village/setup/setup_generator.rb +67 -0
  25. data/lib/generators/village/setup/templates/2001-01-01-example-article.markdown +8 -0
  26. data/lib/generators/village/setup/templates/example-page.markdown +10 -0
  27. data/lib/generators/village/setup/templates/views/articles/_addthis.html.haml +8 -0
  28. data/lib/generators/village/setup/templates/views/articles/_analytics.html.haml +13 -0
  29. data/lib/generators/village/setup/templates/views/articles/_article.html.haml +25 -0
  30. data/lib/generators/village/setup/templates/views/articles/_comments.html.haml +8 -0
  31. data/lib/generators/village/setup/templates/views/articles/_feed_link.html.haml +2 -0
  32. data/lib/generators/village/setup/templates/views/articles/_sidebar.html.haml +13 -0
  33. data/lib/generators/village/setup/templates/views/articles/index.atom.builder +26 -0
  34. data/lib/generators/village/setup/templates/views/articles/index.html.haml +11 -0
  35. data/lib/generators/village/setup/templates/views/articles/index.rss.builder +31 -0
  36. data/lib/generators/village/setup/templates/views/articles/show.html.haml +9 -0
  37. data/lib/generators/village/setup/templates/views/pages/show.html.haml +1 -0
  38. data/lib/generators/village/setup/templates/views/village.css +72 -0
  39. data/lib/generators/village/setup/templates/views/village.html.haml +22 -0
  40. data/lib/generators/village/setup/templates/village_config.yml +81 -0
  41. data/lib/village.rb +4 -0
  42. data/lib/village/article.rb +125 -0
  43. data/lib/village/attributes.rb +21 -0
  44. data/lib/village/config.rb +53 -0
  45. data/lib/village/engine.rb +11 -0
  46. data/lib/village/file_model.rb +83 -0
  47. data/lib/village/page.rb +10 -0
  48. data/lib/village/routes.rb +16 -0
  49. metadata +158 -0
@@ -0,0 +1,21 @@
1
+ module Village
2
+ module Attributes
3
+
4
+ attr_accessor :attributes
5
+
6
+ private
7
+
8
+ def method_missing(method, *args)
9
+ if @attributes.include?(method)
10
+ @attributes[method]
11
+ elsif method =~ /(.*)\=/ and !args.empty?
12
+ @attributes[$1] = args.first
13
+ elsif method =~ /(.*)\?/
14
+ @attributes[$1].present?
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ require 'yaml'
2
+
3
+ module Village
4
+ class Config
5
+ extend Village::Attributes
6
+
7
+ def self.initialize_configurations(path = "#{Rails.root}/config/village_config.yml")
8
+ if File.exists? path and @attributes.nil?
9
+ @attributes = YAML::load(IO.read(path)).with_indifferent_access
10
+ @attributes.reverse_merge!(default_attributes)
11
+ end
12
+ end
13
+
14
+ def self.default_attributes
15
+ {
16
+ :permalink_regex =>
17
+ {
18
+ :day => %r[\d{4}/\d{2}/\d{2}/[^/]+],
19
+ :month => %r[\d{4}/\d{2}/[^/]+],
20
+ :year => %r[\d{4}/[^/]+],
21
+ :slug => %r[[^/]+]
22
+ },
23
+ :permalink_format => :day,
24
+ :file_extensions => ["markdown", "erb", "haml"],
25
+ :layout => "village",
26
+ :page_size => 10
27
+ }
28
+ end
29
+
30
+ def self.clone(*keys)
31
+ unless @attributes.nil?
32
+ options = @attributes.clone
33
+ options.keep_if { |key,value| keys.include?(key.to_sym) } unless keys.nil?
34
+ options
35
+ else
36
+ {}
37
+ end
38
+ end
39
+
40
+ def self.village_permalink_regex(options)
41
+ @attributes[:permalink_format] = options[:permalink_format]
42
+ @attributes[:permalink_regex].try(:[], options[:permalink_format]) or raise_village_permalink_error
43
+ end
44
+
45
+ private
46
+
47
+ def self.raise_village_permalink_error
48
+ possible_options = @attributes[:permalink_regex].map { |k,v| k.inspect }.join(', ')
49
+ raise "Village Routing Error: Invalid :permalink_format option #{attributes[:permalink_format].inspect} - must be one of the following: #{possible_options}"
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ module Village
2
+
3
+ autoload :Attributes, 'village/attributes'
4
+ autoload :Config, 'village/config'
5
+ autoload :FileModel, 'village/file_model'
6
+ autoload :Article, 'village/article'
7
+ autoload :Page, 'village/page'
8
+
9
+ class Engine < ::Rails::Engine
10
+ end
11
+ end
@@ -0,0 +1,83 @@
1
+ require 'tilt'
2
+
3
+ module Village
4
+ class FileModel
5
+ extend ActiveModel::Naming
6
+ include Village::Attributes
7
+
8
+ attr_accessor :content_path, :to_param, :folders, :slug, :extension
9
+
10
+ def initialize(path)
11
+ @content_path, @to_param, @folders, @slug, @extension = path.match(/^#{Rails.root}\/(#{self.class::CONTENT_PATH})\/((.*\/)?(.*))(\.[^.]+)$/).captures
12
+ content = File.read(path)
13
+ @attributes = Village::Config.clone(:title, :subtitle, :author, :layout)
14
+ if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
15
+ @attributes.merge! YAML.load($1)
16
+ @attributes[:content] = content[($1.size + $2.size)..-1]
17
+ else
18
+ @attributes[:content] = content
19
+ end
20
+ @attributes = (@attributes || {}).with_indifferent_access
21
+ end
22
+
23
+ def self.create_class_methods_on(klass)
24
+ klass.instance_eval do
25
+ def all
26
+ @files ||= Dir.glob("#{Rails.root}/#{self::CONTENT_PATH}/**/*.{#{Village::Config.file_extensions.join(',')}}").map do |filename|
27
+ new filename
28
+ end
29
+ end
30
+
31
+ def where(conditions = {})
32
+ conditions = conditions.symbolize_keys
33
+ conditions.assert_valid_keys :to_param
34
+ all.select do |article|
35
+ conditions.all? do |key, value|
36
+ article.send(key) == value
37
+ end
38
+ end
39
+ end
40
+
41
+ def find(id)
42
+ where(:to_param => id).first or raise_missing_template(id.inspect)
43
+ end
44
+
45
+ def first
46
+ all.first
47
+ end
48
+
49
+ def last
50
+ all.last
51
+ end
52
+
53
+ def reset!
54
+ @files = nil
55
+ end
56
+
57
+ private
58
+ def raise_missing_template(id)
59
+ if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
60
+ raise ActionView::MissingTemplate.new(
61
+ [self::CONTENT_PATH], id, "Invalid ID", false, ActionView::Template.template_handler_extensions)
62
+ else
63
+ raise ActionView::MissingTemplate.new(
64
+ [self::CONTENT_PATH], id, "Invalid ID", false)
65
+ end
66
+ end
67
+ end # end child.instance_eval
68
+ end # end self.create_class_methods_on
69
+
70
+ def content_html
71
+ Tilt[@extension].new { @attributes[:content] }.render.html_safe if @attributes[:content].present?
72
+ end
73
+
74
+ def to_s
75
+ "#{@attributes[:title]} (#{@to_param})"
76
+ end
77
+
78
+ def to_key
79
+ [@to_param]
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,10 @@
1
+ module Village
2
+ class Page < FileModel
3
+
4
+ CONTENT_PATH = "app/views/pages"
5
+
6
+ self.superclass.create_class_methods_on(Village::Page)
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,16 @@
1
+ class ActionDispatch::Routing::Mapper
2
+
3
+ def village(controller,options = {})
4
+ Village::Config.initialize_configurations
5
+ case controller
6
+ when :articles
7
+ options.reverse_merge!({ :as => :articles, :permalink_format => :day, :controller => 'village/articles' })
8
+ get "/#{options[:as]}(.:format)(/categories/:category)(/tags/:tag)(/:year(/:month(/:day)))" => "#{options[:controller]}#index", :as => :village_articles, :constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/, :tag => /[^\/]+/, :category => /[^\/]+/ }
9
+ get "/#{options[:as]}/*id" => "#{options[:controller]}#show", :as => :village_article, :constraints => { :id => Village::Config.village_permalink_regex(options) }
10
+ when :pages
11
+ options.reverse_merge!({ :as => :pages, :controller => 'village/pages' })
12
+ match "/#{options[:as]}/*id" => "#{options[:controller]}#show", :as => :village_page, :format => false
13
+ end
14
+ end
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: village
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fajri Fachriansyah
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2153619120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153619120
25
+ - !ruby/object:Gem::Dependency
26
+ name: haml
27
+ requirement: &2153618060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2153618060
36
+ - !ruby/object:Gem::Dependency
37
+ name: tilt
38
+ requirement: &2153617260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2153617260
47
+ - !ruby/object:Gem::Dependency
48
+ name: kaminari
49
+ requirement: &2153616600 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.12.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2153616600
58
+ - !ruby/object:Gem::Dependency
59
+ name: gravtastic
60
+ requirement: &2153615900 !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: *2153615900
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: &2153615440 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *2153615440
80
+ description: Simple static content pages and blog engine for Rails 3.
81
+ email: fajri82@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - app/controllers/village/articles_controller.rb
87
+ - app/controllers/village/pages_controller.rb
88
+ - app/views/layouts/village.html.haml
89
+ - app/views/village/articles/_addthis.html.haml
90
+ - app/views/village/articles/_analytics.html.haml
91
+ - app/views/village/articles/_article.html.haml
92
+ - app/views/village/articles/_comments.html.haml
93
+ - app/views/village/articles/_feed_link.html.haml
94
+ - app/views/village/articles/_sidebar.html.haml
95
+ - app/views/village/articles/index.atom.builder
96
+ - app/views/village/articles/index.html.haml
97
+ - app/views/village/articles/index.rss.builder
98
+ - app/views/village/articles/show.html.haml
99
+ - app/views/village/pages/show.html.haml
100
+ - lib/generators/base.rb
101
+ - lib/generators/village/articles/articles_generator.rb
102
+ - lib/generators/village/articles/USAGE
103
+ - lib/generators/village/setup/setup_generator.rb
104
+ - lib/generators/village/setup/templates/2001-01-01-example-article.markdown
105
+ - lib/generators/village/setup/templates/example-page.markdown
106
+ - lib/generators/village/setup/templates/views/articles/_addthis.html.haml
107
+ - lib/generators/village/setup/templates/views/articles/_analytics.html.haml
108
+ - lib/generators/village/setup/templates/views/articles/_article.html.haml
109
+ - lib/generators/village/setup/templates/views/articles/_comments.html.haml
110
+ - lib/generators/village/setup/templates/views/articles/_feed_link.html.haml
111
+ - lib/generators/village/setup/templates/views/articles/_sidebar.html.haml
112
+ - lib/generators/village/setup/templates/views/articles/index.atom.builder
113
+ - lib/generators/village/setup/templates/views/articles/index.html.haml
114
+ - lib/generators/village/setup/templates/views/articles/index.rss.builder
115
+ - lib/generators/village/setup/templates/views/articles/show.html.haml
116
+ - lib/generators/village/setup/templates/views/pages/show.html.haml
117
+ - lib/generators/village/setup/templates/views/village.css
118
+ - lib/generators/village/setup/templates/views/village.html.haml
119
+ - lib/generators/village/setup/templates/village_config.yml
120
+ - lib/generators/village/setup/USAGE
121
+ - lib/village/article.rb
122
+ - lib/village/attributes.rb
123
+ - lib/village/config.rb
124
+ - lib/village/engine.rb
125
+ - lib/village/file_model.rb
126
+ - lib/village/page.rb
127
+ - lib/village/routes.rb
128
+ - lib/village.rb
129
+ - MIT-LICENSE
130
+ - Rakefile
131
+ - Gemfile
132
+ - Guardfile
133
+ - README.md
134
+ homepage: https://github.com/fajrif/village
135
+ licenses: []
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project: village
154
+ rubygems_version: 1.8.10
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: Simple static content pages and blog engine for Rails 3.
158
+ test_files: []