Skip to content

Commit

Permalink
git subrepo clone git@github.com:ijcd/volt-editable-text.git gems/vol…
Browse files Browse the repository at this point in the history
…t-editable_text

subrepo:
  subdir:   "gems/volt-editable_text"
  merged:   "fb3c997"
upstream:
  origin:   "git@github.com:ijcd/volt-editable-text.git"
  branch:   "master"
  commit:   "fb3c997"
git-subrepo:
  version:  "0.2.3"
  origin:   "https://github.com/Homebrew/homebrew.git"
  commit:   "fdc0570"
  • Loading branch information
ijcd committed Nov 12, 2015
1 parent 9b8aa1a commit 16e2c4c
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gems/volt-editable_text/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
11 changes: 11 additions & 0 deletions gems/volt-editable_text/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = git@github.com:ijcd/volt-editable-text.git
branch = master
commit = fb3c99731e0d72fe0e9ff5acea427f4f5bf724c5
parent = 9b8aa1a9f4f30ac3c718d904b395c3db7133ccaf
cmdver = 0.2.3
4 changes: 4 additions & 0 deletions gems/volt-editable_text/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in volt-editable-text.gemspec
gemspec
23 changes: 23 additions & 0 deletions gems/volt-editable_text/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Volt Editable Text Component

**Note** Currently this only supports Volt 0.8.x, updates for 0.9.x coming soon.

Provides a component that displays text, but becomes editable in a field when clicked on.

## Usage

Add this line to your application's Gemfile:

gem 'volt-editable-text'

And then execute:

$ bundle

Then require it as a component in any components' dependencies.rb you want to use it in.

component 'editable-text'

Finally, use the tag.

<:editable-text value="{{_some_value}}" />
1 change: 1 addition & 0 deletions gems/volt-editable_text/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
1 change: 1 addition & 0 deletions gems/volt-editable_text/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.9
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module EditableText
class MainController < Volt::ModelController
attr_accessor :section
reactive_accessor :toggled

def index
self.toggled = false
end

def body_element
Element.find('body')
end

def toggle_editing
self.toggled = !toggled

if toggled
# Editing enabled, bind a listener for when they click on the document to disable
# it again.
body_element.on('click.editabletext') do |event|
# Find the id for the text field inside of this component.
clicked_id = Element.find(section.container_node).find('input').id

if clicked_id != event.target.id
# Didn't click inside of the edit text field, toggle back.
toggle_editing
end
end
else
body_element.off('click.editabletext')
end
end

def edit(event)
if event.key_code == 13
#for some reason .stop or stop_propagation thow the following error:
#undefined method `stop_propagation' for #<Volt::JSEvent:7672>

#event.stop_propagation

toggle_editing
end
end

def value=(newvalue)
attrs.value = newvalue
end

def value
return attrs.value
end

def size
return attrs.value.size
end

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<:Body>
{{if toggled}}
<input type="text" e-keypress="edit(event)" size="{{size}}" value="{{value}}" />
{{else}}
<span e-click="toggle_editing">{{value}}</span>
{{end}}
9 changes: 9 additions & 0 deletions gems/volt-editable_text/lib/volt/editable/text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "volt/editable/text/version"

class Volt
class Editable
class Text
# Your code goes here...
end
end
end
24 changes: 24 additions & 0 deletions gems/volt-editable_text/volt-editable-text.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

version = File.read(File.expand_path('../VERSION', __FILE__)).strip


Gem::Specification.new do |spec|
spec.name = "volt-editable-text"
spec.version = version
spec.authors = ["Ryan Stout"]
spec.email = ["ryan@agileproductions.com"]
spec.summary = %q{Volt component that gives a :editable-text control which shows text, and lets you edit the text when it is clicked on.}
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "volt", "~> 0.8.23"
spec.add_development_dependency "rake"
end

0 comments on commit 16e2c4c

Please sign in to comment.