radiant-fabulator-extension 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.0.5 2010-09-11
2
+ * 1 major enhancement:
3
+ * Library management under Fabulator tab
4
+
5
+ N.B.: This update requires a database migration to add the library table.
6
+
1
7
  === 0.0.4 2010-09-07
2
8
 
3
9
  * 1 major enhancement:
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  gem.email = "jgsmith@tamu.edu"
8
8
  gem.homepage = "http://github.com/jgsmith/radiant-fabulator"
9
9
  gem.authors = ["James Smith"]
10
- gem.add_dependency('fabulator', '>= 0.0.7')
10
+ gem.add_dependency('fabulator', '>= 0.0.8')
11
11
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
12
  end
13
13
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -0,0 +1,22 @@
1
+ module Admin
2
+ module Fabulator
3
+ class LibrariesController < Admin::ResourceController
4
+ only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
5
+ :when => [:designer, :admin],
6
+ :denied_url => { :controller => 'admin/pages', :action => 'index' },
7
+ :denied_message => 'You must have designer privileges to perform this action.'
8
+
9
+ def model_class
10
+ FabulatorLibrary
11
+ end
12
+
13
+ def show
14
+ respond_to do |format|
15
+ format.xml { super }
16
+ format.html { redirect_to edit_admin_fabulator_libraries_path(params[:id]) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,36 @@
1
+ class FabulatorContext < ActiveRecord::Base
2
+ #serialize :context
3
+ belongs_to :page
4
+ belongs_to :user
5
+
6
+ def self.find_by_page(p)
7
+ if p.request.session[:user_id].blank?
8
+ c = self.first(:conditions => [
9
+ 'page_id = ? AND session = ? AND (user_id IS NULL OR user_id=0)',
10
+ p.id, p.request.session[:session_id]
11
+ ] )
12
+ else
13
+ c = self.first(:conditions => [
14
+ 'page_id = ? AND session = ? AND user_id = ?',
15
+ p.id, p.request.session[:session_id], p.request.session[:user_id]
16
+ ] )
17
+ end
18
+ if c.nil? && !p.request.session[:user_id].blank?
19
+ c = self.first(:conditions => [
20
+ 'page_id = ? AND session = ?',
21
+ p.id, p.request.session[:session_id]
22
+ ] )
23
+ if !c.nil? && c.user.nil?
24
+ c.update_attribute(:user_id, p.request.session[:user_id])
25
+ end
26
+ end
27
+ p.fabulator_context = c.context unless c.nil?
28
+ return c unless c.nil?
29
+ self.new(
30
+ :context => YAML::dump(p.fabulator_context),
31
+ :page_id => p.id,
32
+ :user_id => p.request.session[:user_id],
33
+ :session => p.request.session[:session_id]
34
+ )
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ class FabulatorLibrary < ActiveRecord::Base
2
+ validates_presence_of :name
3
+ validates_uniqueness_of :name
4
+
5
+ belongs_to :updated_by, :class_name => 'User'
6
+ belongs_to :created_by, :class_name => 'User'
7
+
8
+ serialize :compiled_xml
9
+
10
+ before_save :compile_xml
11
+
12
+ def compile_xml
13
+ lib = Fabulator::Lib::Lib.new
14
+ begin
15
+ lib.compile_xml(self.xml)
16
+ lib.register_library
17
+ rescue => e
18
+ # add error
19
+ Rails.logger.info("Error compiling library: #{e}")
20
+ end
21
+ self.compiled_xml = lib
22
+ end
23
+ end
@@ -93,8 +93,12 @@ class FabulatorPage < Page
93
93
  if p.name != XML_PART_NAME
94
94
  super
95
95
  else
96
- # check if page part was updated since page -- might need to recompile
97
-
96
+ FabulatorLibrary.all.each do |library|
97
+ if library.compiled_xml.is_a?(Fabulator::Lib::Lib)
98
+ library.compiled_xml.register_library
99
+ end
100
+ end
101
+
98
102
  sm = self.state_machine
99
103
  return '' if sm.nil?
100
104
 
@@ -0,0 +1,23 @@
1
+ - form_for [:admin, @fabulator_library], :html => {:onsubmit_status => onsubmit_status(@fabulator_library)} do |f|
2
+ = f.hidden_field :lock_version
3
+ = render_region :form_top
4
+ .form_area
5
+ - render_region :form do |form|
6
+ - form.edit_title do
7
+ %p.title
8
+ = f.label :name
9
+ = f.text_field :name, :class => 'textbox activate', :maxlength => 100
10
+ - form.edit_content do
11
+ %p.content
12
+ = f.label :xml, "Definition"
13
+ ~ f.text_area :xml, :class => "textarea large", :style => "width: 100%"
14
+ - render_region :form_bottom do |form_bottom|
15
+ - form_bottom.edit_buttons do
16
+ %p.buttons{:style=>"clear: left"}
17
+ = save_model_button(@fabulator_library, :label => 'Create Library')
18
+ = save_model_and_continue_editing_button(@fabulator_library)
19
+ or
20
+ = link_to 'Cancel', admin_fabulator_libraries_url
21
+ - form_bottom.edit_timestamp do
22
+ %p.updated_line
23
+ = updated_stamp @fabulator_library
@@ -0,0 +1,9 @@
1
+ - @page_title = @fabulator_library.name + ' Library - ' + default_page_title
2
+
3
+ - body_classes << "reversed"
4
+
5
+ - render_region :main do |main|
6
+ - main.edit_header do
7
+ %h1 Edit Library Definition
8
+ - main.edit_form do
9
+ = render :partial => 'form'
@@ -0,0 +1,33 @@
1
+ - @page_title = 'Library - ' + default_page_title
2
+
3
+ .outset
4
+ - render_region :top
5
+ %table#libraries.index
6
+ %thead
7
+ %tr
8
+ - render_region :thead do |thead|
9
+ - thead.title_header do
10
+ %th.filter Library
11
+ - thead.modify_header do
12
+ %th.modify Modify
13
+ %tbody
14
+ - if @fabulator_libraries.any?
15
+ - @fabulator_libraries.each do |library|
16
+ %tr.node.level_1
17
+ - render_region :tbody do |tbody|
18
+ - tbody.title_cell do
19
+ %td.snippet
20
+ = image('snippet', :alt => '')
21
+ %span= link_to library.name, edit_admin_fabulator_library_url(library)
22
+ - tbody.modify_cell do
23
+ %td.remove
24
+ = link_to image('remove', :alt => 'Remove Library'), remove_admin_fabulator_library_url(library)
25
+ - else
26
+ %tr
27
+ %td.note{:colspan => admin.fabulator_library.index.tbody.length} No Libraries
28
+
29
+ - render_region :bottom do |bottom|
30
+ - bottom.new_button do
31
+ #actions
32
+ %ul
33
+ %li= link_to "New Library", { :controller => 'admin/fabulator/libraries', :action => 'new' }
@@ -0,0 +1,7 @@
1
+ - body_classes << "reversed"
2
+
3
+ - render_region :main do |main|
4
+ - main.edit_header do
5
+ %h1 New Library
6
+ - main.edit_form do
7
+ = render :partial => 'form'
@@ -0,0 +1,19 @@
1
+ %h1 Remove Library
2
+
3
+ %p
4
+ Are you sure you want to
5
+ %strong.warning permanently remove
6
+ the following library?
7
+
8
+ %table.index#workflows
9
+ %tbody
10
+ %tr.node.level_1
11
+ %td.library
12
+ = image('snippet', :alt => "")
13
+ %span.title= @fabulator_library.name
14
+
15
+ - form_for [:admin, @fabulator_library], :html => {:method => :delete, :onsubmit_status=>"Removing library&#8230;"} do
16
+ %p.buttons
17
+ %input.button{:type=>"submit", :value=>"Delete Library"}/
18
+ or
19
+ = link_to 'Cancel', admin_fabulator_libraries_url
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.namespace 'admin' do |admin|
3
+ admin.namespace 'fabulator', :member => { :remove => :get } do |fab|
4
+ fab.resources :libraries
5
+ end
6
+ end
7
+ # map.namespace 'api' do |api|
8
+ # api.resources :libraries
9
+ # end
10
+ end
11
+
@@ -0,0 +1,17 @@
1
+ class CreateFabulatorLibrariesTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :fabulator_libraries do |t|
4
+ t.string :name, :null => false
5
+ t.integer :lock_version, :default => 0
6
+ t.text :xml
7
+ t.text :compiled_xml
8
+ t.references :updated_by
9
+ t.references :created_by
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :fabulator_libraries
16
+ end
17
+ end
@@ -1,6 +1,7 @@
1
1
  $: << File.expand_path(File.dirname(__FILE__))+'/lib'
2
2
 
3
3
  require 'fabulator'
4
+ require 'fabulator/lib'
4
5
  require 'fabulator/template'
5
6
  require 'fabulator/radiant'
6
7
 
@@ -25,18 +26,27 @@ class FabulatorExtension < Radiant::Extension
25
26
  FabulatorPage
26
27
 
27
28
  tab 'Fabulator' do
29
+ add_item("Libraries", "/admin/fabulator/libraries")
28
30
  end
31
+ Radiant::AdminUI.class_eval do
32
+ attr_accessor :libraries
33
+ alias_method :fabulator_library, :libraries
34
+ end
35
+ admin.libraries = load_default_fabulator_library_regions
29
36
 
30
37
  PagePart.class_eval do
31
38
  after_save :compile_xml
32
39
 
33
- # validates_each :content do |record, attr, value|
34
- # record.compile_xml
35
- # end
36
-
37
40
  def compile_xml
38
41
  if self.page.class_name == 'FabulatorPage' &&
39
42
  self.name == FabulatorExtension::XML_PART_NAME
43
+
44
+ FabulatorLibrary.all.each do |library|
45
+ if library.compiled_xml.is_a?(Fabulator::Lib::Lib)
46
+ library.compiled_xml.register_library
47
+ end
48
+ end
49
+
40
50
  old_compiled_xml = self.page.compiled_xml
41
51
  if self.content.nil? || self.content == ''
42
52
  self.page.compiled_xml = nil
@@ -73,4 +83,22 @@ class FabulatorExtension < Radiant::Extension
73
83
  end
74
84
  end
75
85
  end
86
+
87
+ def load_default_fabulator_library_regions
88
+ returning OpenStruct.new do |library|
89
+ library.edit = Radiant::AdminUI::RegionSet.new do |edit|
90
+ edit.main.concat %w{edit_header edit_form}
91
+ edit.form.concat %w{edit_title edit_content}
92
+ edit.form_bottom.concat %w{edit_buttons edit_timestamp}
93
+ end
94
+ library.index = Radiant::AdminUI::RegionSet.new do |index|
95
+ index.top.concat %w{help_text}
96
+ index.thead.concat %w{title_header modify_header}
97
+ index.tbody.concat %w{title_cell modify_cell}
98
+ index.bottom.concat %w{new_button}
99
+ end
100
+ library.new = library.edit
101
+ end
102
+ end
103
+
76
104
  end
@@ -0,0 +1,9 @@
1
+ module Fabulator
2
+ module Radiant
3
+ module Actions
4
+ class RequireAuth
5
+
6
+ end
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-fabulator-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-07 00:00:00 +00:00
18
+ date: 2010-09-11 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 17
29
+ hash: 15
30
30
  segments:
31
31
  - 0
32
32
  - 0
33
- - 7
34
- version: 0.0.7
33
+ - 8
34
+ version: 0.0.8
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  description: Creates a Fabulator page type allowing applications to be built using the fabulator engine.
@@ -48,12 +48,23 @@ files:
48
48
  - README.rdoc
49
49
  - Rakefile
50
50
  - VERSION
51
+ - app/controllers/admin/fabulator/libraries_controller.rb
52
+ - app/models/fabulator_context.rb
53
+ - app/models/fabulator_library.rb
51
54
  - app/models/fabulator_page.rb
55
+ - app/views/admin/fabulator/libraries/_form.html.haml
56
+ - app/views/admin/fabulator/libraries/edit.html.haml
57
+ - app/views/admin/fabulator/libraries/index.html.haml
58
+ - app/views/admin/fabulator/libraries/new.html.haml
59
+ - app/views/admin/fabulator/libraries/remove.html.haml
60
+ - config/routes.rb
52
61
  - db/migrate/001_add_fabulator_fields.rb
53
62
  - db/migrate/002_create_fabulator_contexts_table.rb
63
+ - db/migrate/003_create_fabulator_libraries_table.rb
54
64
  - fabulator_extension.rb
55
65
  - lib/fabulator/radiant.rb
56
66
  - lib/fabulator/radiant/actions.rb
67
+ - lib/fabulator/radiant/actions/require_auth.rb
57
68
  - lib/radiant-fabulator-extension.rb
58
69
  has_rdoc: true
59
70
  homepage: http://github.com/jgsmith/radiant-fabulator