activeadmin-blog 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.gitignore +20 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +215 -0
  4. data/README.md +162 -0
  5. data/Rakefile +7 -0
  6. data/activeadmin-blog.gemspec +30 -0
  7. data/app/controllers/activeadmin_blog/posts_controller.rb +50 -0
  8. data/app/models/activeadmin_blog/blog_category.rb +23 -0
  9. data/app/models/activeadmin_blog/blog_post.rb +81 -0
  10. data/app/views/activeadmin_blog/posts/_footer.html.erb +10 -0
  11. data/app/views/activeadmin_blog/posts/_header.html.erb +11 -0
  12. data/app/views/activeadmin_blog/posts/_post.html.erb +31 -0
  13. data/app/views/activeadmin_blog/posts/archive.html.erb +9 -0
  14. data/app/views/activeadmin_blog/posts/category.html.erb +9 -0
  15. data/app/views/activeadmin_blog/posts/feed.rss.builder +18 -0
  16. data/app/views/activeadmin_blog/posts/index.html.erb +9 -0
  17. data/app/views/activeadmin_blog/posts/search.html.erb +9 -0
  18. data/app/views/activeadmin_blog/posts/show.html.erb +35 -0
  19. data/app/views/activeadmin_blog/posts/tag.html.erb +9 -0
  20. data/app/views/admin/categories/_form.html.erb +26 -0
  21. data/app/views/admin/posts/_categories.html.erb +18 -0
  22. data/config/routes.rb +9 -0
  23. data/install.sh +160 -0
  24. data/lib/activeadmin-blog.rb +8 -0
  25. data/lib/activeadmin-blog/engine.rb +5 -0
  26. data/lib/activeadmin-blog/version.rb +3 -0
  27. data/lib/generators/activeadmin_blog/install_generator.rb +40 -0
  28. data/lib/generators/activeadmin_blog/templates/README +5 -0
  29. data/lib/generators/activeadmin_blog/templates/admin/blog_categories.rb +86 -0
  30. data/lib/generators/activeadmin_blog/templates/admin/blog_posts.rb +101 -0
  31. data/lib/generators/activeadmin_blog/views_generator.rb +16 -0
  32. data/vendor/assets/javascripts/activeadmin_blog.js.coffee +56 -0
  33. data/vendor/assets/stylesheets/activeadmin_blog.css.scss +51 -0
  34. metadata +180 -0
@@ -0,0 +1,8 @@
1
+ require "nokogiri"
2
+ require "mongoid_slug"
3
+ require "mongoid_search"
4
+ require "activeadmin-mongoid"
5
+ require "activeadmin-mongoid-reorder"
6
+
7
+ require "activeadmin-blog/version"
8
+ require "activeadmin-blog/engine"
@@ -0,0 +1,5 @@
1
+ module ActiveadminBlog
2
+ class Engine < Rails::Engine
3
+ isolate_namespace ActiveadminBlog
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveadminBlog
2
+ VERSION = "0.4.0"
3
+ end
@@ -0,0 +1,40 @@
1
+ module ActiveadminBlog
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::NamedBase
4
+ desc << "Description:\n Copies blog source files to your application's app directory, adds routes and missing gems."
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_files
9
+ # admin
10
+ puts "Installing admin:"
11
+ copy_file "admin/blog_categories.rb", "app/admin/blog_categories.rb"
12
+ copy_file "admin/blog_posts.rb", "app/admin/blog_posts.rb"
13
+ end
14
+
15
+ def add_assets
16
+ if File.exist?('app/assets/javascripts/active_admin.js')
17
+ insert_into_file "app/assets/javascripts/active_admin.js",
18
+ "//= require activeadmin_blog\n", :after => "base\n"
19
+ else
20
+ puts "It doesn't look like you've installed activeadmin: active_admin.js is missing.\nPlease install it and try again."
21
+ end
22
+
23
+ if File.exist?('app/assets/stylesheets/active_admin.css.scss')
24
+ insert_into_file "app/assets/stylesheets/active_admin.css.scss",
25
+ "//= require activeadmin_blog\n", :before => "// Active Admin CSS Styles\n"
26
+ else
27
+ puts "It doesn't look like you've installed activeadmin: active_admin.scss is missing.\nPlease install it and try again."
28
+ end
29
+ end
30
+
31
+ def mount_engine
32
+ route "mount ActiveadminBlog::Engine => '/#{file_name}'"
33
+ end
34
+
35
+ def show_congrats
36
+ readme("README")
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ Blog app for active admin is now installed. Please run bundle to install missing gems. Then run settings installer:
2
+
3
+ rails g activeadmin_settings:install
4
+
5
+ Thanks for installing activeadmin-blog!
@@ -0,0 +1,86 @@
1
+ ActiveAdmin.register ActiveadminBlog::BlogCategory, :as => "Category" do
2
+ menu false
3
+
4
+ actions :all, :except => [:index]
5
+
6
+ controller do
7
+ def create
8
+ create! do |format|
9
+ format.html { redirect_to admin_posts_path }
10
+ end
11
+ end
12
+
13
+ def update
14
+ update! do |format|
15
+ format.html { redirect_to admin_posts_path }
16
+ end
17
+ end
18
+
19
+ def destroy
20
+ destroy! do |format|
21
+ format.html { redirect_to admin_posts_path }
22
+ end
23
+ end
24
+
25
+ defaults :finder => :find_by_permalink
26
+ end
27
+
28
+ show :title => :name do
29
+ ol :id => "category_posts_page" do
30
+ li :class => "links" do
31
+ link_to "All Posts", admin_posts_path, :class => "all-posts-button"
32
+ end
33
+ li do
34
+ if category.blog_posts.size > 0
35
+ table_for(category.blog_posts, {:class => "index_table category_posts"}) do |t|
36
+
37
+ t.column("") do |p| # Blog post featured image thumbnail
38
+ url = p.featured_image.thumb.url
39
+ if url.nil?
40
+ url = "http://placehold.it/118x100&text=NO+IMAGE"
41
+ end
42
+ image_tag(url, :alt => p.title, :size=>"118x100")
43
+ end
44
+
45
+ t.column("Title") do |p|
46
+ html = "<p><strong>#{p.title}</strong><br/><em>#{truncate(p.excerpt, :length => 90)}</em></p>"
47
+
48
+ if not p.tags.empty?
49
+ html << "Tags: <em>" + p.tags.gsub(',', ', ') + "</em><br/>"
50
+ end
51
+
52
+ if p.categories.size > 0
53
+ html << "Published in: " + p.categories.collect{|c| link_to(c.name, admin_category_path(c))}.join(", ")
54
+ end
55
+ html.html_safe
56
+ end
57
+
58
+ t.column("Status") do |p|
59
+ """#{p.date.to_s.gsub('-', '/')}<br/>
60
+ <i>#{p.published ? 'Published' : 'Not Finished'}</i>""".html_safe
61
+ end
62
+
63
+ t.column "" do |p|
64
+ link_to("Edit", edit_admin_post_path(p), :class => "member_link") +
65
+ link_to("Delete", admin_post_path(p), :class => "member_link", :method => :delete, :confirm => "Are you sure?")
66
+ end
67
+ end
68
+ else
69
+ p "No posts here yet."
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ sidebar :categories, :only => :show do
76
+ render :partial => "admin/posts/categories", :locals => { :categories => ActiveadminBlog::BlogCategory.all }
77
+ end
78
+
79
+ form do |f|
80
+ render :partial => "form", :locals => { :f => f }
81
+ end
82
+
83
+ collection_action :reorder, :method => :put do
84
+ render :text => resource_class.reorder_objects(params[:ids])
85
+ end
86
+ end
@@ -0,0 +1,101 @@
1
+ ActiveAdmin.register ActiveadminBlog::BlogPost, :as => "Post" do
2
+ menu :label => "Blog"
3
+
4
+ actions :all, :except => [:show]
5
+
6
+ # Scopes
7
+ scope :published, :default => true
8
+ scope :ideas
9
+
10
+ controller do
11
+ defaults :finder => :find_by_permalink
12
+ end
13
+
14
+ index do
15
+ column("") do |p| # Blog post featured image thumbnail
16
+ url = p.featured_image.thumb.url
17
+ if url.nil?
18
+ url = "http://placehold.it/118x100&text=NO+IMAGE"
19
+ end
20
+ image_tag(url, :alt => p.title, :size=>"118x100")
21
+ end
22
+
23
+ column("Title") do |p|
24
+ html = "<p><strong>#{p.title}</strong><br/><em>#{truncate(p.excerpt, :length => 90)}</em></p>"
25
+
26
+ if not p.tags.empty?
27
+ html << "Tags: <em>" + p.tags.gsub(',', ', ') + "</em><br/>"
28
+ end
29
+
30
+ if p.categories.size > 0
31
+ html << "Published in: " + p.categories.collect{|c| link_to(c.name, admin_category_path(c))}.join(", ")
32
+ end
33
+ html.html_safe
34
+ end
35
+
36
+ column("Status") do |p|
37
+ """#{p.date.to_s.gsub('-', '/')}<br/>
38
+ <i>#{p.published ? 'Published' : 'Not Finished'}</i>""".html_safe
39
+ end
40
+
41
+ default_actions
42
+ end
43
+
44
+ sidebar :categories, :only => :index do
45
+ render :partial => "categories", :locals => { :categories => ActiveadminBlog::BlogCategory.all }
46
+ end
47
+
48
+ form do |f|
49
+ f.inputs "Title" do
50
+ f.input :title, :required => true
51
+ end
52
+ f.inputs "Content" do
53
+ f.input :content, :as => :text,
54
+ :input_html => { :class => "redactor" }
55
+ end
56
+ f.inputs "Details" do
57
+
58
+ if f.object.has_featured_image?
59
+ featured_image_hint = image_tag f.object.featured_image.thumb.url, :size => "118x100"
60
+ else
61
+ featured_image_hint = ""
62
+ end
63
+ f.input :featured_image, :hint => featured_image_hint
64
+
65
+ if f.object.has_featured_image?
66
+ f.input :remove_featured_image, :as => :boolean
67
+ end
68
+
69
+ unless f.object.new?
70
+ f.input :permalink
71
+ end
72
+
73
+ f.input :published, :as => :select,
74
+ :label => "State",
75
+ :collection => [["published", "true"], ["not finished", "false"]],
76
+ :include_blank => false,
77
+ :input_html => { :class => "select2" }
78
+
79
+ f.input :date, :input_html => { :class => "datepicker", :placeholder => "Click field to pick date" }
80
+
81
+ categories = ActiveadminBlog::BlogCategory.all
82
+ if categories.size > 0
83
+ f.input :categories, :as => :select,
84
+ :label => "Published in",
85
+ :input_html => { :multiple => true, :class => "select2" },
86
+ :collection => categories,
87
+ :include_blank => false,
88
+ :hint => "Click on field and select category from dropdown"
89
+ end
90
+
91
+ f.input :tags, :hint => "Select from the list or type a new one and press ENTER",
92
+ :input_html => { "data-url" => "/admin/posts/tags" }
93
+ end
94
+ f.buttons
95
+ end
96
+
97
+ collection_action :tags, :method => :get do
98
+ tags = ActiveadminBlog::BlogPost.all.collect{ |p| p.tags }.join(",").split(',').uniq
99
+ render :json => tags
100
+ end
101
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveadminBlog
2
+ module Generators
3
+ class ViewsGenerator < Rails::Generators::NamedBase
4
+ desc << "Description:\n Copies blog templates to your application."
5
+
6
+ source_root File.expand_path('../../../../app/views/activeadmin_blog/posts', __FILE__)
7
+
8
+ def copy_default_views
9
+ filename_pattern = File.join self.class.source_root, "*.html.erb"
10
+ Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
11
+ copy_file f, "app/views/blog/#{f}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,56 @@
1
+ #= require activeadmin_reorder_table
2
+ #= require activeadmin_settings
3
+
4
+ if !Array.prototype.last
5
+ Array.prototype.last = () -> return this[this.length - 1]
6
+
7
+ $ ->
8
+ # Fix header menu for category pages
9
+ if $('.admin_categories').length > 0
10
+ $('#header #blog').addClass("current")
11
+
12
+ # Enable redactor
13
+ $('.redactor').redactor
14
+ imageUpload: "/redactor_rails/pictures"
15
+ imageGetJson: "/redactor_rails/pictures"
16
+
17
+ # Enable select2
18
+ $('.select2').select2
19
+ minimumResultsForSearch: 10
20
+
21
+ tags_input = $("#post_tags")
22
+ if tags_input.length > 0
23
+ tags_url = tags_input.attr("data-url")
24
+ $.get tags_url, (tags) => tags_input.select2({tags: tags })
25
+
26
+ # Reorder functionality
27
+ $ ->
28
+ categories_sortable_options = (url) ->
29
+ options =
30
+ stop: (e, ui) ->
31
+ # Select object ids from the table rows
32
+ # -------------------------------------
33
+ ids = []
34
+ $(this).find('li').each ->
35
+ id_attr = $(this).attr('id')
36
+ if id_attr
37
+ id = id_attr.split("_").last()
38
+ ids.push(id)
39
+
40
+ params =
41
+ ids: ids
42
+ _method: "put"
43
+ authenticity_token: $('meta[name=csrf-token]').attr('content')
44
+
45
+ $.post url, params, (data) ->
46
+ if data != "ok"
47
+ alert 'Error happended. Please contact devs.'
48
+ return options
49
+
50
+ reorder_method_url = "/admin/categories/reorder"
51
+ $("#blog_categories_list")
52
+ .sortable(categories_sortable_options(reorder_method_url))
53
+ .disableSelection()
54
+
55
+
56
+
@@ -0,0 +1,51 @@
1
+ //= require activeadmin_settings
2
+
3
+ #edit_post, #new_post {
4
+ #post_content_input label { display:none; }
5
+ #post_title_input label { display:none; }
6
+
7
+ #post_title { font-size:2em; }
8
+
9
+ #post_category_ids { width:76%; }
10
+ #post_draft { width:160px; }
11
+ #post_date { width:138px; }
12
+ }
13
+
14
+ #posts.index_table {
15
+ tr th:first-child, tr th:last-child { width:118px; }
16
+ }
17
+
18
+ #categories.index_table {
19
+ tr th:last-child { width:118px; }
20
+ }
21
+
22
+ .admin_categories .category_posts {
23
+ tr th:first-child, tr th:last-child { width:118px; }
24
+ }
25
+
26
+ .admin_posts {
27
+ #categories_sidebar_section {
28
+ }
29
+ }
30
+
31
+ #categories_sidebar_section {
32
+ margin-top:36px;
33
+ ul {
34
+ margin:0px; padding:0px;
35
+ list-style:none;
36
+ }
37
+ .action-buttons {
38
+ float:right;
39
+ }
40
+ }
41
+
42
+ #category_posts_page {
43
+ margin:0px;
44
+ padding:0px;
45
+ list-style:none;
46
+
47
+ .links {
48
+ height:22px;
49
+ margin-bottom:14px;
50
+ }
51
+ }
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-blog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Kravets
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid_slug
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mongoid_search
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.8
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.8
62
+ - !ruby/object:Gem::Dependency
63
+ name: activeadmin-mongoid-reorder
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: activeadmin-mongoid
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: activeadmin-settings
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: ''
111
+ email: santyor@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - .gitignore
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - README.md
120
+ - Rakefile
121
+ - activeadmin-blog.gemspec
122
+ - app/controllers/activeadmin_blog/posts_controller.rb
123
+ - app/models/activeadmin_blog/blog_category.rb
124
+ - app/models/activeadmin_blog/blog_post.rb
125
+ - app/views/activeadmin_blog/posts/_footer.html.erb
126
+ - app/views/activeadmin_blog/posts/_header.html.erb
127
+ - app/views/activeadmin_blog/posts/_post.html.erb
128
+ - app/views/activeadmin_blog/posts/archive.html.erb
129
+ - app/views/activeadmin_blog/posts/category.html.erb
130
+ - app/views/activeadmin_blog/posts/feed.rss.builder
131
+ - app/views/activeadmin_blog/posts/index.html.erb
132
+ - app/views/activeadmin_blog/posts/search.html.erb
133
+ - app/views/activeadmin_blog/posts/show.html.erb
134
+ - app/views/activeadmin_blog/posts/tag.html.erb
135
+ - app/views/admin/categories/_form.html.erb
136
+ - app/views/admin/posts/_categories.html.erb
137
+ - config/routes.rb
138
+ - install.sh
139
+ - lib/activeadmin-blog.rb
140
+ - lib/activeadmin-blog/engine.rb
141
+ - lib/activeadmin-blog/version.rb
142
+ - lib/generators/activeadmin_blog/install_generator.rb
143
+ - lib/generators/activeadmin_blog/templates/README
144
+ - lib/generators/activeadmin_blog/templates/admin/blog_categories.rb
145
+ - lib/generators/activeadmin_blog/templates/admin/blog_posts.rb
146
+ - lib/generators/activeadmin_blog/views_generator.rb
147
+ - vendor/assets/javascripts/activeadmin_blog.js.coffee
148
+ - vendor/assets/stylesheets/activeadmin_blog.css.scss
149
+ homepage: https://github.com/alexkravets/activeadmin-blog
150
+ licenses:
151
+ - MIT
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ segments:
163
+ - 0
164
+ hash: 2654380653042337041
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ segments:
172
+ - 0
173
+ hash: 2654380653042337041
174
+ requirements: []
175
+ rubyforge_project: nowarning
176
+ rubygems_version: 1.8.24
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: Blog app on the top of activeadmin and mongoid.
180
+ test_files: []