beef-text_elements 0.1.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Steve England
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.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = text_elements
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Steve England. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "text_elements"
8
+ gem.summary = %Q{For all those bits of text that don't need a full cms}
9
+ gem.email = "steve@wearebeef.co.uk"
10
+ gem.homepage = "http://github.com/beef/text_elements"
11
+ gem.authors = ["Steve England"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "text_elements #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,33 @@
1
+ class Admin::TextElementsController < Admin::BaseController
2
+ sortable_attributes :var, :value
3
+
4
+ def index
5
+ @text_elements = TextElement.paginate :page => params[:page], :per_page => 20, :order => sort_order
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @text_elements }
10
+ end
11
+ end
12
+
13
+
14
+ def show
15
+ @text_element = TextElement.find(params[:id])
16
+ end
17
+
18
+ def update
19
+ @text_element = TextElement.find(params[:id])
20
+
21
+ respond_to do |format|
22
+ if @text_element.update_attributes(params[:text_element])
23
+ flash[:notice] = 'Text Element was successfully updated.'
24
+ format.html { redirect_to(admin_text_elements_url) }
25
+ format.xml { head :ok }
26
+ else
27
+ format.html { render :action => "show" }
28
+ format.xml { render :xml => @text_element.errors, :status => :unprocessable_entity }
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,25 @@
1
+ class TextElement < ActiveRecord::Base
2
+ acts_as_textiled :value
3
+
4
+ validates_presence_of :var
5
+
6
+ #get with the variable as the called method
7
+ def self.method_missing(method, *args)
8
+ method_name = method.to_s
9
+ super(method, *args)
10
+
11
+ rescue NoMethodError
12
+ #retrieve a value
13
+ te = object(method_name)
14
+ "<div class=\"ugc\">#{te.value || dummy_text}</div>"
15
+ end
16
+
17
+ #retrieve the actual Setting record
18
+ def self.object(var_name)
19
+ TextElement.find_or_create_by_var(var_name.to_s)
20
+ end
21
+
22
+ def self.dummy_text
23
+ '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>'
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ <h1>Listing Text Elements</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <%= sortable_table_header :name => "Title", :sort => "var" %>
7
+ <%= sortable_table_header :name => "Content", :sort => "value" %>
8
+ <%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
9
+ <th colspan="3">Actions</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+
14
+ <% for text_element in @text_elements %>
15
+ <tr>
16
+ <td class="title"><%=h text_element.var.titleize %></td>
17
+ <td><%= truncate(text_element.value_plain, 50, '&hellip;') %></td>
18
+ <td class="date"><%= text_element.updated_at.to_formatted_s(:short) %></td>
19
+ <td><%= link_to 'Edit', [:admin, text_element], :class => 'edit' %></td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ <tfoot>
24
+ <tr>
25
+ <%= sortable_table_header :name => "Title", :sort => "var" %>
26
+ <%= sortable_table_header :name => "Content", :sort => "value" %>
27
+ <%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
28
+ <th colspan="3">Actions</th>
29
+ </tr>
30
+ </tfoot>
31
+ </table>
32
+
33
+
34
+ <%= will_paginate @text_elements %>
35
+
36
+
37
+ <% content_for :search do %>
38
+ <h2>Search</h2>
39
+
40
+ <% form_for :search, :html => {:method => 'get'} do |f| -%>
41
+ <p>
42
+ <%= f.label :title %><br/>
43
+ <%= f.text_field :title %>
44
+ </p>
45
+ <p>
46
+ <%= f.label :text %><br/>
47
+ <%= f.text_field :text %>
48
+ </p>
49
+ <p>
50
+ <%= f.submit 'Search', :disable_with => 'Searching...' %>
51
+ </p>
52
+ <% end %>
53
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <h1>Editing Text Element <%= @text_element.var.titleize %></h1>
2
+
3
+ <% form_for @text_element, :url => admin_text_element_path(@text_element) do |f| -%>
4
+
5
+ <p>
6
+ <%= f.label :value, "Content" %><br/>
7
+ <%= f.text_area :value, :class => 'editor' %>
8
+ </p>
9
+
10
+ <p class="submission"><%= f.submit "Go Live", :disable_with => 'Publishing...' %>
11
+ <% end -%>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.namespace(:admin) do |admin|
3
+ admin.resources :text_elements
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class CreateTextElements < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :text_elements do |t|
4
+ t.string :var, :null => false
5
+ t.text :value
6
+
7
+ t.timestamps
8
+ end
9
+ add_index :text_elements, :var
10
+ end
11
+
12
+ def self.down
13
+ remove_index :text_elements, :var
14
+ drop_table :text_elements
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class TextElementsMigrationGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.migration_template "migration.rb",
6
+ 'db/migrate',
7
+ :migration_file_name => "create_text_elements"
8
+ end
9
+ end
10
+
11
+ end
File without changes
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'text_elements'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TextElementsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beef-text_elements
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve England
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: steve@wearebeef.co.uk
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - app/controllers/admin/text_elements_controller.rb
33
+ - app/models/text_element.rb
34
+ - app/views/admin/text_elements/index.html.erb
35
+ - app/views/admin/text_elements/show.html.erb
36
+ - config/routes.rb
37
+ - generators/text_elements_migration/templates/migration.rb
38
+ - generators/text_elements_migration/text_elements_migration_generator.rb
39
+ - lib/text_elements.rb
40
+ - test/test_helper.rb
41
+ - test/text_elements_test.rb
42
+ has_rdoc: false
43
+ homepage: http://github.com/beef/text_elements
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: For all those bits of text that don't need a full cms
68
+ test_files:
69
+ - test/test_helper.rb
70
+ - test/text_elements_test.rb