bop 0.0.1

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Spanner Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # Bop
2
+
3
+ *Blocks on Pages*. Very simple, very lovely html5 CMS that you can plug into any Rails app. Bop is designed
4
+ from the ground up as an engine: for standalone CMS you need `bopulate`, which is an equally minimal
5
+ multi-domain hosting package designed for the lazy. Also, doesn't exist yet.
6
+
7
+ Bop includes modern html5 editing tools, asset-management, content reuse, and drag and drop editing of
8
+ page trees.
9
+
10
+ ## Status
11
+
12
+ Brand new, very alpha, avoid!
13
+
14
+ ## Requirements
15
+
16
+ A rails 3.2 app with devise and cancan.
17
+
18
+ ## Conventions
19
+
20
+ Bop works in a very simple way:
21
+
22
+ * Anything can have a page tree;
23
+ * Pages have a template;
24
+ * Templates define spaces;
25
+ * Spaces have one or more blocks in them;
26
+ * Blocks have types, which determine the presentation of their content.
27
+
28
+ Out of the box, you get three types of block: html, asset or list. It's very easy to add more.
29
+
30
+ ## Templates
31
+
32
+ At the moment all our page templates are in Liquid. Other templating engines will be supported soon, including
33
+ radius. Blocks can be edited in markdown, textile, html or haml. Also, soon, radius.
34
+
35
+ ## Installation
36
+
37
+ In your gemfile:
38
+
39
+ gem "bop"
40
+
41
+ To migrate:
42
+
43
+ rake bop:install:migrations
44
+ rake db:migrate
45
+
46
+ ## Usage
47
+
48
+ Add this line to one or more of your model classes:
49
+
50
+ has_pages
51
+
52
+ ## Customisation (not yet)
53
+
54
+ To bring Bop javascript, stylesheets and block_type views into your app for customisation:
55
+
56
+ rake bop:customise
57
+
58
+ ## Extension (not yet)
59
+
60
+ Bop will be extensible from your initializers in these constrained ways:
61
+
62
+ * block types can be added with a simple declaration and the necessary view/edit templates
63
+ * markup types can be added for templates or blocks or both
64
+
65
+ Before long there will also be a simple API for defining new data types or asset types and custom blocks to go
66
+ with them. The interior of Bop is very simple so it's also easy to monkey over if you like that sort of thing.
67
+
68
+ ## Migration from radiant (not yet)
69
+
70
+ Once radius support is worked in, we will support the automated import of radiant sites. This will bring in
71
+ pages, layouts, snippets and assets, but non-core radiant extensions will not be supported. Persuade their
72
+ authors to turn them into bop extensions instead.
73
+
74
+ ## Copyright
75
+
76
+ Copyright William Ross for Spanner Ltd, 2012
77
+ Released under the MIT license: See LICENSE.
78
+
79
+
80
+
81
+
82
+
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Bop'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Bop
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bop
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ class Bop::Asset < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+
4
+ has_attached_file :file
5
+
6
+ end
@@ -0,0 +1,20 @@
1
+ class Bop::Block < ActiveRecord::Base
2
+ attr_accessible :title, :content, :type
3
+
4
+ belongs_to :user
5
+ has_many :block_properties
6
+ has_many :placed_blocks
7
+ has_many :pages, :through => :placed_blocks
8
+
9
+ def block_type
10
+ Bop::BlockType[type]
11
+ end
12
+
13
+ def render(context, view="show")
14
+ template(view).render(context)
15
+ end
16
+
17
+ def template(view)
18
+ block_type.template(view)
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ class Bop::BlockProperty < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+
4
+ belongs_to :block
5
+ end
@@ -0,0 +1,39 @@
1
+ # At the moment block types are just parameterised template-finders.
2
+ #
3
+
4
+ class Bop::BlockType
5
+ @@types = []
6
+ @@type_lookup = {}
7
+ @template = {}
8
+ attr_reader :name
9
+
10
+ def initialize(name, options = {})
11
+ options = options.symbolize_keys
12
+ @name = name
13
+ @@types.push self
14
+ @@type_lookup[@name] = self
15
+ end
16
+
17
+ def template(name)
18
+ unless @templates[name]
19
+ # Here we will need to support various file types and should probably just hook into ActionView. That's going to be fun.
20
+ tpl = null
21
+ [Bop::Engine.root, Rails.root].each do |root|
22
+ if !tpl && File.exist(root + "app/views/bop/block_types/#{name}.liquid")
23
+ tpl = File.read(root + "app/views/bop/block_types/#{name}.liquid")
24
+ end
25
+ end
26
+ raise Bop::MissingTemplateError unless tpl
27
+ @templates[name] = Liquid::Template.parse(tpl)
28
+ end
29
+ @templates[name]
30
+ end
31
+ end
32
+
33
+ def self.find(type)
34
+ @@type_lookup[type] if type
35
+ end
36
+
37
+ def self.[](type)
38
+ find(type)
39
+ end
@@ -0,0 +1,68 @@
1
+ require 'ancestry'
2
+
3
+ class Bop::Page < ActiveRecord::Base
4
+ attr_accessible :title, :slug, :template_id, :race_id, :asset_id
5
+
6
+ belongs_to :race
7
+ belongs_to :template
8
+ belongs_to :user
9
+ belongs_to :asset
10
+ has_ancestry :orphan_strategy => :destroy
11
+ has_many :placed_blocks
12
+ has_many :blocks, :through => :placed_blocks
13
+
14
+ before_save :ensure_slug
15
+ before_save :receive_context
16
+ after_save :propagate_context
17
+
18
+ validate :title, :presence => true
19
+ # this needs scoping
20
+ validate :slug, :uniqueness => true, :presence => true
21
+
22
+ def inherited_template
23
+ template || parent.inherited_template
24
+ end
25
+
26
+ def inherited_asset
27
+ asset || parent.inherited_asset
28
+ end
29
+
30
+ # currently we only support liquid for page layouts
31
+ def render
32
+ inherited_template.compiled.render(context)
33
+ end
34
+
35
+ # Fixed
36
+ def context
37
+ @context ||= {
38
+ :page => self,
39
+ :asset => inherited_asset,
40
+ :race => race,
41
+ :user => User.current,
42
+ :account => Account.current
43
+ }
44
+ end
45
+
46
+ protected
47
+
48
+ def ensure_slug
49
+ self.slug ||= title.parameterize
50
+ end
51
+
52
+ def receive_context
53
+ if parent
54
+ self.race = parent.race
55
+ self.route = (ancestors + [self]).map(&:slug).join('/')
56
+ else
57
+ self.route = ""
58
+ end
59
+ end
60
+
61
+ def propagate_context
62
+ children.each do |child|
63
+ child.receive_context
64
+ child.save
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,11 @@
1
+ class Bop::PlacedBlock < ActiveRecord::Base
2
+ # attr_accessible :title, :body
3
+
4
+ belongs_to :page
5
+ belongs_to :block
6
+
7
+ scope :in_bucket, lambda { |bucket|
8
+
9
+ }
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ class Bop::Template < ActiveRecord::Base
2
+ attr_accessible :title, :content
3
+
4
+ belongs_to :user
5
+ has_many :pages
6
+
7
+ def compiled
8
+ @template ||= Liquid::Template.parse(content)
9
+ end
10
+
11
+ end
@@ -0,0 +1,2 @@
1
+ <h2>{{block.title}}</h2>
2
+ {{block.content}}
@@ -0,0 +1,3 @@
1
+ Bop::BlockType.new "text"
2
+ Bop::BlockType.new "asset"
3
+ Bop::BlockType.new "list"
@@ -0,0 +1,5 @@
1
+ Bop::Engine.routes.draw do
2
+ end
3
+
4
+ Rails.application.routes.draw do
5
+ end
@@ -0,0 +1,62 @@
1
+ class CreateBopTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :bop_pages do |t|
4
+ t.string :title
5
+ t.string :slug
6
+ t.string :route
7
+ t.string :ancestry
8
+ t.integer :race_id
9
+ t.integer :template_id
10
+ t.integer :asset_id
11
+ t.integer :user_id
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :bop_templates do |t|
16
+ t.string :title
17
+ t.text :content
18
+ t.text :description
19
+ t.string :markup_type
20
+ t.integer :user_id
21
+ t.timestamps
22
+ end
23
+
24
+ create_table :bop_blocks do |t|
25
+ t.string :title
26
+ t.text :content
27
+ t.string :markup_type
28
+ t.string :type
29
+ t.integer :asset_id
30
+ t.integer :user_id
31
+ t.timestamps
32
+ end
33
+
34
+ create_table :bop_assets do |t|
35
+ t.string :title
36
+ t.has_attached_file :file
37
+ t.integer :user_id
38
+ t.timestamps
39
+ end
40
+
41
+ create_table :bop_placed_blocks do |t|
42
+ t.string :bucket
43
+ t.integer :block_id
44
+ t.integer :page_id
45
+ t.timestamps
46
+ end
47
+
48
+ create_table :bop_block_properties do |t|
49
+ t.string :name
50
+ t.string :content
51
+ t.timestamps
52
+ end
53
+
54
+ create_table :bop_publications do |t|
55
+ t.text :rendered_content
56
+ t.integer :page_id
57
+ t.integer :user_id
58
+ t.timestamps
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,49 @@
1
+ require "bop/engine"
2
+ require "bop/tags"
3
+ require "bop/glue"
4
+
5
+ module Bop
6
+ class BopError < StandardError; end
7
+ class MissingRootPageError < BopError; end
8
+ class MissingPageError < BopError; end
9
+ class MissingTemplateError < BopError; end
10
+
11
+ module ClassMethods
12
+ def has_pages
13
+ include InstanceMethods
14
+
15
+ has_many :pages, :class_name => "Bop::Page"
16
+ after_save :ensure_root_page
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def root_page!
22
+ raise Bop::MissingRootPageError unless page = root_page
23
+ page
24
+ end
25
+
26
+ def root_page
27
+ find_page("")
28
+ end
29
+
30
+ def find_page!(route)
31
+ raise Bop::MissingPageError unless page = find_page(route)
32
+ page
33
+ end
34
+
35
+ def find_page(route)
36
+ pages.find_by_route(route)
37
+ end
38
+
39
+ protected
40
+
41
+ def ensure_root_page
42
+ unless root_page
43
+ pages.create(:title => "Home", :slug => "")
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+
@@ -0,0 +1,8 @@
1
+ module Bop
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Bop
4
+ initializer "bop.integration" do
5
+ ActiveRecord::Base.send(:include, Bop::Glue)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Bop
2
+ class BopError < StandardError; ned
3
+ class MissingRootPageError < BopError; end
4
+ class MissingPageError < BopError; end
5
+ class MissingTemplateError < BopError; end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Bop
2
+ module Glue
3
+ def self.included base #:nodoc:
4
+ base.extend ClassMethods
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require "liquid"
2
+
3
+ module Bop
4
+ module Tags
5
+
6
+ class Yield < Liquid::Tag
7
+ def initialize(tag_name, bucket, tokens)
8
+ super
9
+ @bucket = bucket || "main"
10
+ end
11
+
12
+ def render(context)
13
+ if page = context[:page]
14
+ block_context = context.dup.merge(:block => self)
15
+ page.blocks_for(@bucket.downcase).map{ |block| block.render(block_context) }
16
+ end
17
+ end
18
+ end
19
+
20
+ Liquid::Template.register_tag('yield', Yield)
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Bop
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bop do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - William Ross
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.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: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: ancestry
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: liquid
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
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: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
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
+ description: Blocks on Pages. Very simple, very lovely html5 CMS designed from the
95
+ ground up as a rails engine.
96
+ email:
97
+ - will@spanner.org
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - app/assets/javascripts/bop/application.js
103
+ - app/assets/stylesheets/bop/application.css
104
+ - app/controllers/bop/application_controller.rb
105
+ - app/helpers/bop/application_helper.rb
106
+ - app/models/bop/asset.rb
107
+ - app/models/bop/block.rb
108
+ - app/models/bop/block_property.rb
109
+ - app/models/bop/block_type.rb
110
+ - app/models/bop/page.rb
111
+ - app/models/bop/placed_block.rb
112
+ - app/models/bop/template.rb
113
+ - app/views/bop/block_types/text/show.liquid
114
+ - config/initializers/bop.rb
115
+ - config/routes.rb
116
+ - db/migrate/20120809125316_create_bop_tables.rb
117
+ - lib/bop/engine.rb
118
+ - lib/bop/exceptions.rb
119
+ - lib/bop/glue.rb
120
+ - lib/bop/tags.rb
121
+ - lib/bop/version.rb
122
+ - lib/bop.rb
123
+ - lib/tasks/bop_tasks.rake
124
+ - Rakefile
125
+ - README.md
126
+ - LICENSE
127
+ homepage: http://bop.spanner.org
128
+ licenses: []
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.24
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: HTML5 CMS engine for Rails 3.2+
151
+ test_files: []