Apr 242016
 

IA Writer to WordPress

0. Wha?

With the coming of the new doggie into the house, perhaps I will again add more content to the bloggy thing that I have kinda sorta not really been keeping over the last little while.

Probably this has been done by someone else on the Intertubz, but ach, why not. I have some time on my hands, so here are running notes in IA Writer that will make its way to a WordPress post by some means or other. There’s nothing special about IA writer, by the way. Well, there is, but not for the purposes of the WordPress posting. The same code should work with any plain-ish text file coming from any editor.

Why bother? Well, I think that the primary reason a lot of my notes have not made it to the blog is that it is just such a PITA to go out of my way to make a blog posting. If it all just sorta “works” from my usual workflows than that would perhaps be a very different situation. Not that I think I have anything particularly interesting or unique to say

1. This file

Is written in markdown, with metadata at the head:

Title: IA Writer to Wordpress  
Author: yearlus  
Email: [email protected]  
Date: 2016-04-26  
Format: complete  
post_status: draft  
post_date: 2016-04-26
post_title: IA Writer to Wordpress  
category: tech  
post_tag: text, editors, Ruby, code, Wordpress, workflow  


# [%Title]

2. Markdown processors

Four Ruby processors for playing with markdown are briefly alluded to here: markdown-processing-ruby

And I went ahead and played with two of these:

Redcarpet

$ gem install redcarpet -n /usr/local/bin

Kramdown

$ gem install kramdown -n /usr/local/bin

But neither of these processors support (yet!) the metadata blocks of MultiMarkdown. And kramdown does not recognise the back-tick code-fence (“` “`), only the tilda code-fence (~~~ ~~~)

So, install Fletcher Penney’s MultiMarkdown, and test:

$ brew install multimarkdown
$ multimarkdown ~/_scratch/IA-Writer-to-WP-Coleman-Notes.txt > ~/_scratch/IA-Writer-to-WP-Coleman-Notes.html

Gives some very nice HTML, including interpolation of the metadata (of this file), and writing of that metadata:

<head>
    <meta charset="utf-8"/>
    <title>IA Writer to Wordpress</title>
    <meta name="author" content="yearlus"/>
    <meta name="email" content="[email protected]"/>
    <meta name="date" content="2016-04-26"/>
    <meta name="format" content="complete"/>
    <meta name="post_status" content="draft"/>
    <meta name="post_date" content="2016-04-26"/>
    <meta name="post_title" content="IA Writer to Wordpress"/>
    <meta name="category" content="tech"/>
    <meta name="post_tag" content="text, editors, Ruby, code, Wordpress, workflow"/>
</head>

So the process for this exercise seems clear:
1. “~~shell out” to markdown and produce an html file~~
2. process that html with nokogiri
3. post to WordPress

No need to shell out, apparently. tillsc has already built a Ruby extension library around MultiMarkdown, Ruby MultiMarkdown 4, so
I guess the awkward bit would be how best to execute the ruby script that pulls all this together… from a services menu item, maybe? And then how to deal with edits… something in the metadata at the head of the file? A call to getPost call to XML RPC to see if an existing post “matching” (on what criterion?) that about to be posted exists? But what to check on? Is the old post deleted? I suppose when one starts thinking about these things then one might just as well produce an actual interface to WordPress, but why bother when there are so many such things anyway?

Maybe I will look into that… but I am reasonably happy with the fact that this post came from iA Writer, and without too much trouble either. Next up? A horror-show of a MultiMarkdown file in iA Writer to to see how much gets translated into a decent-ish looking post.

3. Code

Posting to WordPress is pretty straightforward. All the heavy lifting is done by the rubypress gem, which makes this sort of thing doggone simple (see what I did there!). Here a block of code from that thing I wrote a while ago that scraped a Koine Greek “Word of the Day” from Ἡ Καινὴ Διαθήκη. Last post here

# ========== Post to Wordpress ==========
if options[:wordpress_write] == 'yes'
  wp = Rubypress::Client.new(
    host:      "#{config['wp']['host']}",
    username:  "#{config['wp']['username']}",
    password:  "#{config['wp']['password']}",
    path:      "#{config['wp']['path']}")

  wp.newPost(
    blog_id:    '0',
    content:    {
      post_status:   'draft',
      post_date:     Time.now,
      post_title:    "#{html_title}",
      terms_names:  {
        post_tag:     ['greek', 'koine', 'κοινή', 'language'],
        category:     ['Greek']
      },
      post_content:  "#{wp_content}"
    }
  )
end
# ========== END WP Post ==========

 


posted with wpiawriter v. 0.1
Apr 212015
 


Install node.js https://nodejs.org/ this will also install the node package manager, npm.

❯ npm update  
❯ npm upgrade  
❯ npm install bootstrap  
❯ npm install jquery
❯ npm install -g grunt-cli
❯ npm install bower

all installed to

/usr/local/lib/node_modules/npm

which is maybe not wehere we want bootstrap for a project particular project. Think we need to install on per-project basis:

❯ cd ~
❯ mkdir code/bootstrap
❯ cd code/bootstrap
❯ bower install bootstrap
❯ cd ~/code/bootstrap/bower_components/bootstrap  
❯ npm install
❯ grunt dist

The bootstrap project working files are now in:

~/code/bootstrap/bower_components/bootstrap/dist

❯ ls
total 16
[email protected] 1 yearlus  502   6.0K Apr 13 06:19 .DS_Store
drwxr-xr-x  8 yearlus  502   272B Apr 13 06:16 css
drwxr-xr-x  7 yearlus  502   238B Apr 13 06:16 fonts
drwxr-xr-x  5 yearlus  502   170B Apr 13 06:16 js





Sep 242014
 

So, I came across this site last night when scouting around for tools/sites that Eldest child might like to use as he gets to grips with programming, that is to do so without my necessarily having to hold his hand. The decisions I might make may or may not be reasonable or even appropriate. Better that he get a variety of experienced feedback from others (I will always be there), and in whatever language he chooses.

exercism.io is, essentially a community. Programming exercise sets, in numerous languages, are submitted and vetted by the community. One downloads these exercises, writes code, and submits waiting for feedback. It is not a learning environment per se, well not in the “instruct me” sense at least.

I find it fascinating because it is NOT based on a spiffy AJAXed-up website with its own editing environment and submit process. One installs a simple CLI tool, and uses that to download and submit to git. Submitted ruby code for calculating hamming distances in genetic sequences this AM to see how it all worked together, and it did. Flawlessly. I guess the downside is that one needs an environment set up on a machine, and a workflow, and #1 Son doesn’t have that yet. That, and I don’t think the problem sets would exactly tickle his curiosity.

There are several options for the CLI program install, one of which uses homebrew. I chose that, and in the process cleaned-up a three-plus-year-old-install of that.

Apr 222013
 

For an online coursera.org course on interactive python from Rice University. 1st project exercise.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import math
import random

def name_to_number(name):
    name = name.lower()
    if name == "rock":
        return 0
    elif name == "spock":
        return 1
    elif name == "paper":
        return 2
    elif name == "lizard":
        return 3
    elif name == "scissors":
        return 4
    else:
        return "Invalid hand sign '" + name + "'!\nplease choose: 'rock', 'Spock', 'paper', 'lizard' or 'scissors'"

def number_to_name(number):
    if number == 0:
        return "rock"
    elif number == 1:
        return "Spock"
    elif number == 2:
        return "paper"
    elif number == 3:
        return "lizard"
    else:
        number == 4
        return "scissors"

   
def rpsls(name):
    player_val = name_to_number(name)
    computer_val = random.randrange(0,5)
   
    mod_val = (player_val - computer_val) % 5  
    if mod_val == 0:
        winner = "Player and computer tie!"
    elif mod_val > 0  and mod_val < 3:
        winner = "Player wins!"
    else:
        winner = "Computer wins!"

    print "Player choosses " + number_to_name(player_val) #+ " (" + str(player_val) + ")"
    print "Computer chooses " + number_to_name(computer_val) #+ " (" + str(computer_val) + ")"
    print winner
    #print mod_val
    print "\n"
 

### OUTPUT ###
rpsls("Rock")
rpsls("scissors")
rpsls("paper")
rpsls("lizard")
rpsls("spock")
Oct 282011
 

Remove RVM, thus making for a cleaner install later:

$ RVM implode

Remove XCode:

$ sudo /Developer/Library/uninstall-devtools –mode=all

XCode is removed since in 4.2, at least, all references to gcc are linked to llvm-gcc (Apple’s) own fork of gcc. llvm will NOT compile ruby.

(One can always re-install from the AppStore later)
download and install GCC-10.7-v2.pkg from https://github.com/kennethreitz/osx-gcc-installer/downloads

This will install just the bare-bones GCC compiler. It can safely be overwritten by XCode if you decide to reinstall it, or simple removed using the same command as that used for removing XCode.
reinstall RVM: http://beginrescueend.com/rvm/install/
Install the package manager “homebrew” from http://mxcl.github.com/homebrew/ and with it install libiconv.

$ brew install libiconv

This will install several files to homebrew’s home directory “/usr/local/cellar
backup /usr/local/lib/libiconv.2.dylib, and copy /usr/local/cellar/libiconv/1.14/lib/libiconv.2.dylib into it’s place in /usr/local/lib

At this point you should have everything in place to install ruby 1.9.2 using RVM:

CC=gcc-4.2 rvm install 1.9.2-p290 --with-iconv-dir=/usr/local/Cellar/libiconv/1.14.1

(RVM does not actually support –with-iconv-dir, if you check the config.log file, but it might someday… in which case the copying of libiconv will be unnecessary)

Now go install gems and rails and anything else you might need.

—–

{my stack overflow comment}

Social Widgets powered by AB-WebLog.com.