homeland 0.0.3

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.
Files changed (35) hide show
  1. data/README.markdown +32 -0
  2. data/app/assets/images/reply.png +0 -0
  3. data/app/assets/javascripts/homeland.coffee +48 -0
  4. data/app/assets/stylesheets/homeland.scss +84 -0
  5. data/app/controllers/homeland/application_controller.rb +14 -0
  6. data/app/controllers/homeland/replies_controller.rb +20 -0
  7. data/app/controllers/homeland/topics_controller.rb +124 -0
  8. data/app/helpers/homeland/application_helper.rb +27 -0
  9. data/app/helpers/homeland/topics_helper.rb +8 -0
  10. data/app/models/homeland/node.rb +24 -0
  11. data/app/models/homeland/reply.rb +29 -0
  12. data/app/models/homeland/section.rb +17 -0
  13. data/app/models/homeland/topic.rb +43 -0
  14. data/app/views/homeland/replies/edit.html.erb +28 -0
  15. data/app/views/homeland/shared/_error_messages.html.erb +11 -0
  16. data/app/views/homeland/topics/_base.html.erb +4 -0
  17. data/app/views/homeland/topics/_form.html.erb +23 -0
  18. data/app/views/homeland/topics/_sidebar.html.erb +65 -0
  19. data/app/views/homeland/topics/_topic.html.erb +26 -0
  20. data/app/views/homeland/topics/edit.html.erb +11 -0
  21. data/app/views/homeland/topics/feed.builder +20 -0
  22. data/app/views/homeland/topics/index.html.erb +51 -0
  23. data/app/views/homeland/topics/new.html.erb +11 -0
  24. data/app/views/homeland/topics/show.html.erb +88 -0
  25. data/config/routes.rb +16 -0
  26. data/lib/generators/homeland/install/templates/initializer.rb +8 -0
  27. data/lib/generators/homeland/install/templates/javascripts/jquery.hotkeys.js +99 -0
  28. data/lib/generators/homeland/install/templates/javascripts/jquery.timeago.js +147 -0
  29. data/lib/generators/homeland/install/templates/locales/homeland.zh-CN.yml +14 -0
  30. data/lib/generators/homeland/install_generator.rb +45 -0
  31. data/lib/generators/homeland/views_generator.rb +23 -0
  32. data/lib/homeland.rb +6 -0
  33. data/lib/homeland/engine.rb +32 -0
  34. data/lib/homeland/setting.rb +37 -0
  35. metadata +91 -0
@@ -0,0 +1,147 @@
1
+ /*
2
+ * timeago: a jQuery plugin, version: 0.9.3 (2011-01-21)
3
+ * @requires jQuery v1.2.3 or later
4
+ *
5
+ * Timeago is a jQuery plugin that makes it easy to support automatically
6
+ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
7
+ *
8
+ * For usage and examples, visit:
9
+ * http://timeago.yarp.com/
10
+ *
11
+ * Licensed under the MIT:
12
+ * http://www.opensource.org/licenses/mit-license.php
13
+ *
14
+ * Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
15
+ */
16
+ (function($) {
17
+ $.timeago = function(timestamp) {
18
+ if (timestamp instanceof Date) {
19
+ return inWords(timestamp);
20
+ } else if (typeof timestamp === "string") {
21
+ return inWords($.timeago.parse(timestamp));
22
+ } else {
23
+ return inWords($.timeago.datetime(timestamp));
24
+ }
25
+ };
26
+ var $t = $.timeago;
27
+
28
+ $.extend($.timeago, {
29
+ settings: {
30
+ refreshMillis: 60000,
31
+ allowFuture: false,
32
+ strings: {
33
+ prefixAgo: null,
34
+ prefixFromNow: null,
35
+ suffixAgo: "前",
36
+ suffixFromNow: "刚刚",
37
+ seconds: "1秒",
38
+ minute: "1分钟",
39
+ minutes: "%d分钟",
40
+ hour: "1小时",
41
+ hours: "%d小时",
42
+ day: "1天",
43
+ days: "%d天",
44
+ month: "1月",
45
+ months: "%d月",
46
+ year: "1年",
47
+ years: "%d年",
48
+ numbers: []
49
+ }
50
+ },
51
+ inWords: function(distanceMillis) {
52
+ var $l = this.settings.strings;
53
+ var prefix = $l.prefixAgo;
54
+ var suffix = $l.suffixAgo;
55
+ if (this.settings.allowFuture) {
56
+ if (distanceMillis < 0) {
57
+ prefix = $l.prefixFromNow;
58
+ suffix = $l.suffixFromNow;
59
+ }
60
+ distanceMillis = Math.abs(distanceMillis);
61
+ }
62
+
63
+ var seconds = distanceMillis / 1000;
64
+ var minutes = seconds / 60;
65
+ var hours = minutes / 60;
66
+ var days = hours / 24;
67
+ var years = days / 365;
68
+
69
+ function substitute(stringOrFunction, number) {
70
+ var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
71
+ var value = ($l.numbers && $l.numbers[number]) || number;
72
+ return string.replace(/%d/i, value);
73
+ }
74
+
75
+ var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
76
+ seconds < 90 && substitute($l.minute, 1) ||
77
+ minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
78
+ minutes < 90 && substitute($l.hour, 1) ||
79
+ hours < 24 && substitute($l.hours, Math.round(hours)) ||
80
+ hours < 48 && substitute($l.day, 1) ||
81
+ days < 30 && substitute($l.days, Math.floor(days)) ||
82
+ days < 60 && substitute($l.month, 1) ||
83
+ days < 365 && substitute($l.months, Math.floor(days / 30)) ||
84
+ years < 2 && substitute($l.year, 1) ||
85
+ substitute($l.years, Math.floor(years));
86
+
87
+ return $.trim([prefix, words, suffix].join(""));
88
+ },
89
+ parse: function(iso8601) {
90
+ var s = $.trim(iso8601);
91
+ s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
92
+ s = s.replace(/-/,"/").replace(/-/,"/");
93
+ s = s.replace(/T/," ").replace(/Z/," UTC");
94
+ s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
95
+ return new Date(s);
96
+ },
97
+ datetime: function(elem) {
98
+ // jQuery's `is()` doesn't play well with HTML5 in IE
99
+ var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
100
+ var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
101
+ return $t.parse(iso8601);
102
+ }
103
+ });
104
+
105
+ $.fn.timeago = function() {
106
+ var self = this;
107
+ self.each(refresh);
108
+
109
+ var $s = $t.settings;
110
+ if ($s.refreshMillis > 0) {
111
+ setInterval(function() { self.each(refresh); }, $s.refreshMillis);
112
+ }
113
+ return self;
114
+ };
115
+
116
+ function refresh() {
117
+ var data = prepareData(this);
118
+ if (!isNaN(data.datetime)) {
119
+ $(this).text(inWords(data.datetime));
120
+ }
121
+ return this;
122
+ }
123
+
124
+ function prepareData(element) {
125
+ element = $(element);
126
+ if (!element.data("timeago")) {
127
+ element.data("timeago", { datetime: $t.datetime(element) });
128
+ var text = $.trim(element.text());
129
+ if (text.length > 0) {
130
+ element.attr("title", text);
131
+ }
132
+ }
133
+ return element.data("timeago");
134
+ }
135
+
136
+ function inWords(date) {
137
+ return $t.inWords(distance(date));
138
+ }
139
+
140
+ function distance(date) {
141
+ return (new Date().getTime() - date.getTime());
142
+ }
143
+
144
+ // fix for IE6 suckage
145
+ document.createElement("abbr");
146
+ document.createElement("time");
147
+ }(jQuery));
@@ -0,0 +1,14 @@
1
+ 'zh-CN':
2
+ mongoid:
3
+ models:
4
+ homeland/topic: "话题"
5
+ homeland/reply: "回复"
6
+ homeland/section: "大节点"
7
+ homeland/node: "节点"
8
+ attributes:
9
+ homeland/topic:
10
+ title: "标题"
11
+ body: "正文"
12
+ user_id: "用户"
13
+ homeland/reply:
14
+ body: "回复内容"
@@ -0,0 +1,45 @@
1
+ require 'rails/generators'
2
+ module Homeland
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path("../install/templates", __FILE__)
7
+
8
+ def add_initializer
9
+ path = "#{Rails.root}/config/initializers/homeland.rb"
10
+ if File.exists?(path)
11
+ puts "Skipping config/initializers/homeland.rb creation, as file already exists!"
12
+ else
13
+ puts "Adding Homeland initializer (config/initializers/homeland.rb)..."
14
+ template "initializer.rb", path
15
+ end
16
+ end
17
+
18
+ def add_javascripts
19
+ %w(jquery.hotkeys.js jquery.timeago.js).each do |fname|
20
+ path = "#{Rails.root}/vendor/assets/javascripts/#{fname}"
21
+ if File.exists?(path)
22
+ puts "Skipping vendor/assets/javascripts/#{fname} creation, as file already exists!"
23
+ else
24
+ puts "Adding assets (vendor/assets/javascripts/#{fname})..."
25
+ template "javascripts/#{fname}", path
26
+ end
27
+ end
28
+ end
29
+
30
+ def add_locales
31
+ %w(zh-CN.yml).each do |fname|
32
+ path = "#{Rails.root}/config/locales/homeland.#{fname}"
33
+ if File.exists?(path)
34
+ puts "Skipping config/locales/homeland.#{fname} creation, as file already exists!"
35
+ else
36
+ puts "Adding assets (config/locales/homeland.#{fname})..."
37
+ template "locales/homeland.#{fname}", path
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require 'rails/generators'
3
+ module Homeland
4
+ module Generators
5
+ class ViewsGenerator < Rails::Generators::Base #:nodoc:
6
+ source_root File.expand_path("../../../../app/views/homeland", __FILE__)
7
+ desc "Used to copy Homeland's views to your application's views."
8
+
9
+ def copy_views
10
+ view_directory :replies
11
+ view_directory :shared
12
+ view_directory :topic_mailer
13
+ view_directory :topics
14
+ end
15
+
16
+ protected
17
+
18
+ def view_directory(name)
19
+ directory name.to_s, "app/views/homeland/#{name}"
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/homeland.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "rails"
2
+ require "homeland/setting"
3
+ require "homeland/engine"
4
+
5
+ module Homeland
6
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ module ::Homeland
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Homeland
5
+
6
+ class << self
7
+ attr_accessor :root
8
+ def root
9
+ @root ||= Pathname.new(File.expand_path('../../', __FILE__))
10
+ end
11
+ end
12
+
13
+ config.to_prepare do
14
+ if Homeland.user_class
15
+ Homeland.user_class.has_many :topics, :class_name => "Homeland::Topic", :foreign_key => "user_id"
16
+ Homeland.user_class.has_many :replies, :class_name => "Homeland::Reply", :foreign_key => "user_id"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ begin
24
+ require 'kaminari'
25
+ rescue LoadError
26
+ begin
27
+ require 'will_paginate'
28
+ rescue LoadError
29
+ puts "Please add the kaminari or will_paginate gem to your application's Gemfile. The Forem engine needs either kaminari or will_paginate in order to paginate."
30
+ exit
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ require 'active_support/core_ext/kernel/singleton_class'
3
+
4
+ module Homeland
5
+ mattr_accessor :app_name, :per_page, :user_class, :current_user_method, :require_user_method,
6
+ :user_path_method, :user_avatar_method
7
+
8
+ class << self
9
+ def app_name
10
+ @@app_name || "Forum"
11
+ end
12
+
13
+ def per_page
14
+ @@per_page || 20
15
+ end
16
+
17
+ def user_class
18
+ (@@user_class || "User").constantize
19
+ end
20
+
21
+ def current_user_method
22
+ @@current_user_method || "current_user"
23
+ end
24
+
25
+ def require_user_method
26
+ @@require_user_method || "require_user"
27
+ end
28
+
29
+ def user_path_method
30
+ @@user_path_method || "user_path"
31
+ end
32
+
33
+ def user_avatar_method
34
+ @@user_avatar_method || "avatar"
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: homeland
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70327648887040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70327648887040
25
+ description: A new style forum for small communitys.
26
+ email:
27
+ - huacnlee@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/generators/homeland/install/templates/initializer.rb
33
+ - lib/generators/homeland/install/templates/javascripts/jquery.hotkeys.js
34
+ - lib/generators/homeland/install/templates/javascripts/jquery.timeago.js
35
+ - lib/generators/homeland/install/templates/locales/homeland.zh-CN.yml
36
+ - lib/generators/homeland/install_generator.rb
37
+ - lib/generators/homeland/views_generator.rb
38
+ - lib/homeland/engine.rb
39
+ - lib/homeland/setting.rb
40
+ - lib/homeland.rb
41
+ - app/assets/images/reply.png
42
+ - app/assets/javascripts/homeland.coffee
43
+ - app/assets/stylesheets/homeland.scss
44
+ - app/controllers/homeland/application_controller.rb
45
+ - app/controllers/homeland/replies_controller.rb
46
+ - app/controllers/homeland/topics_controller.rb
47
+ - app/helpers/homeland/application_helper.rb
48
+ - app/helpers/homeland/topics_helper.rb
49
+ - app/models/homeland/node.rb
50
+ - app/models/homeland/reply.rb
51
+ - app/models/homeland/section.rb
52
+ - app/models/homeland/topic.rb
53
+ - app/views/homeland/replies/edit.html.erb
54
+ - app/views/homeland/shared/_error_messages.html.erb
55
+ - app/views/homeland/topics/_base.html.erb
56
+ - app/views/homeland/topics/_form.html.erb
57
+ - app/views/homeland/topics/_sidebar.html.erb
58
+ - app/views/homeland/topics/_topic.html.erb
59
+ - app/views/homeland/topics/edit.html.erb
60
+ - app/views/homeland/topics/feed.builder
61
+ - app/views/homeland/topics/index.html.erb
62
+ - app/views/homeland/topics/new.html.erb
63
+ - app/views/homeland/topics/show.html.erb
64
+ - config/routes.rb
65
+ - README.markdown
66
+ homepage: http://github.com/huacnlee/homeland
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.6
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.10
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A new style forum for small communitys.
90
+ test_files: []
91
+ has_rdoc: