Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

#!/usr/bin/python 

# -*- coding: utf-8 -*- 

""" _dryxTBS_scaffolding.py 

============================= 

:Summary: 

    Layout / scaffolding partial for the dryxTwitterBootstrap module 

 

:Author: 

    David Young 

 

:Date Created: 

    March 27, 2013 

 

:dryx syntax: 

    - ``xxx`` = come back here and do some more work 

    - ``_someObject`` = a 'private' object that should only be changed for debugging 

 

:Notes: 

    - If you have any questions requiring this script please email me: d.r.young@qub.ac.uk """ 

 

 

################################################################### 

# CLASSES                                                         # 

################################################################### 

 

################################################################### 

# PUBLIC FUNCTIONS                                                # 

################################################################### 

## SNIPPET CREATED 

## LAST MODIFIED : April 11, 2013 

## CREATED : April 11, 2013 

## AUTHOR : DRYX 

def htmlDocument(content=''): 

    """The doctype and html tags 

 

    **Key Arguments:** 

        - ``content`` -- the head and body of the html page 

 

    **Return:** 

        - ``doctype`` -- the HTML5 doctype """ 

 

    htmlDocument = \ 

        """Content-Type: text/html\n 

        <!DOCTYPE html> 

        <html lang="en"> 

            %s 

        </html> 

    """ \ 

        % (content, ) 

    return htmlDocument 

 

 

## SNIPPET CREATED 

## LAST MODIFIED : May 28, 2013 

## CREATED : May 28, 2013 

## AUTHOR : DRYX 

def head( 

    relativeUrlBase='', 

    mainCssFileName="main.css", 

    pageTitle="", 

    extras="", 

    ): 

    """Generate an html head element for your webpage 

 

    **Key Arguments:** 

        ``relativeUrlBase`` -- relative base url for js, css, image folders 

        ``pageTitle`` -- well, the page title! 

        ``mainCssFileName`` -- css file name 

        ``extras`` -- any extra info to be included in the ``head`` element 

 

    **Return:** 

        - ``head`` -- the head """ 

 

    cssUrl = relativeUrlBase + '/assets/styles/css/' + mainCssFileName 

    cssLink = """ 

        <link rel="stylesheet" href="%s" type="text/css" /> 

    """ % (cssUrl, ) 

 

    head = """ 

    <!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 

    <!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]--> 

    <!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]--> 

    <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> 

    <head> 

        <meta charset="utf-8"> 

        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

        <title>%s</title> 

        <meta name="description" content=""> 

        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

        %s 

        %s 

    </head> 

    """ % (pageTitle, cssLink, extras) 

 

    return head 

 

## SNIPPET CREATED 

## LAST MODIFIED : May 31, 2013 

## CREATED : May 31, 2013 

## AUTHOR : DRYX 

def body( 

        navBar=False, 

        content="", 

        htmlId="", 

        extraAttr="", 

        relativeUrlBase="", 

        responsive=True, 

        googleAnalyticsCode=False, 

        jsFileName="main.js" 

        ): 

    """Generate an HTML body 

 

    **Key Arguments:** 

        - ``navBar`` -- the top navigation bar 

        - ``htmlId`` -- *id* attribute of the body 

        - ``content`` -- body content built from smaller HTML code blocks 

        - ``extraAttr`` -- an extra attributes to be added to the body definition 

        - ``relativeUrlBase`` -- how to get back to the document root 

        - ``responsive`` -- should the webpage be responsive to screen-size? 

        - ``googleAnalyticsCode`` -- google analytics code for the website 

        - ``jsFileName`` -- the name of the main javascript file 

 

    **Return:** 

        - ``body`` -- the body 

    """ 

    if not navBar: 

        navBar = "" 

 

    if googleAnalyticsCode: 

        googleAnalyticsCode = """ 

        <!-- Google Analytics --> 

        <script> 

            var _gaq=[['_setAccount','%s'],['_trackPageview']]; 

            (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; 

            g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; 

            s.parentNode.insertBefore(g,s)}(document,'script')); 

        </script> 

        """ % (googleAnalyticsCode,) 

    else: 

        googleAnalyticsCode = "" 

 

    container = _container( 

        responsive=responsive, 

        content=content, 

        htmlId=False, 

        htmlClass=False, 

        onPhone=True, 

        onTablet=True, 

        onDesktop=True, 

        ) 

 

    body = \ 

        """ 

      <body id="%s" %s> 

      <!--[if lt IE 7]> 

        <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p> 

      <![endif]--> 

        %s 

        %s 

      <script src="%s/assets/js/%s"></script> 

      %s 

      </body><!-- /#%s--> 

      """ \ 

        % ( 

        htmlId, 

        extraAttr, 

        navBar, 

        container, 

        relativeUrlBase, 

        jsFileName, 

        googleAnalyticsCode, 

        htmlId, 

        ) 

 

    return body 

 

## SNIPPET CREATED 

## LAST MODIFIED : March 27, 2013 

## CREATED : March 27, 2013 

## AUTHOR : DRYX 

def row( 

    responsive=True, 

    columns='', 

    htmlId=False, 

    htmlClass=False, 

    onPhone=True, 

    onTablet=True, 

    onDesktop=True, 

    ): 

    """Create a row using the Twitter Bootstrap static layout grid. 

    The static Bootstrap grid system utilizes 12 columns. 

 

    **Key Arguments:** 

        - ``responsive`` -- fluid layout if true, fixed if false 

        - ``columns`` -- coulmns to be included in this row 

        - ``htmlId`` -- the id of the row 

        - ``htmlClass`` -- the class of the row 

        - ``onPhone`` -- does this row get displayed on a phone sized screen 

        - ``onTablet`` -- does this row get displayed on a tablet sized screen 

        - ``onDesktop`` -- does this row get displayed on a desktop sized screen 

 

    **Return:** 

        - ``row`` -- the row """ 

 

    if responsive: 

        responsive = '-fluid' 

    else: 

        responsive = '' 

    if htmlId: 

        htmlId = """id="%s" """ % (htmlId, ) 

    else: 

        htmlId = '' 

    if not htmlClass: 

        htmlClass = '' 

    if onPhone: 

        onPhone = '' 

    else: 

        onPhone = 'hidden-phone' 

    if onTablet: 

        onTablet = '' 

    else: 

        onTablet = 'hidden-tablet' 

    if onDesktop: 

        onDesktop = '' 

    else: 

        onDesktop = 'hidden-desktop' 

    row = """ 

        <div class="row%s %s %s %s %s" %s> 

            %s 

        </div> 

    """ % ( 

        responsive, 

        htmlClass, 

        onPhone, 

        onTablet, 

        onDesktop, 

        htmlId, 

        columns, 

        ) 

    return row 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

# xxxxxxxxxxx-still needs work and snippets-xxxxxxxxxxxxxx 

 

 

 

 

 

 

# xxx-replace 

## LAST MODIFIED : December 17, 2012 

## CREATED : December 17, 2012 

## AUTHOR : DRYX 

 

def get_simple_div(htmlId=None, blockContent=None): 

    """ Generate a basic <div> with block-content 

 

  ****Key Arguments:**** 

    - ``htmlId`` -- the html id attribute 

    - ``blockContent`` -- content to be surrounded by html div tag 

 

  **Return:** 

    - ``div`` """ 

 

  # ############### > IMPORTS ################ 

  # ############### > VARIABLE SETTINGS ###### 

  # ############### >ACTION(S) ################ 

    div = get_html_block(dict( 

        tag='div', 

        htmlId=htmlId, 

        blockContent=blockContent, 

        )) 

    return div 

 

 

# xxx-replace 

## LAST MODIFIED : December 12, 2012 

## CREATED : December 12, 2012 

## AUTHOR : DRYX 

 

def get_javascript_block(jsPath): 

    """ Create a javascript *<script>* html code block 

 

  ****Key Arguments:**** 

    - ``jsPath`` -- path the js file 

 

  **Return:** 

    - ``block`` -- HTML code block """ 

 

  # ############### > IMPORTS ################ 

  # ############### > VARIABLE SETTINGS ###### 

  # ############### >ACTION(S) ################ 

    block = """<script src="%s" type="text/javascript" charset="utf-8"></script>""" % (jsPath, ) 

    return block 

 

 

# xxx-replace 

## LAST MODIFIED : December 11, 2012 

## CREATED : December 11, 2012 

## AUTHOR : DRYX 

 

def get_html_block(attributeDict): 

    """Get an HTML code block (tag) which in turn can be meshed together to build webpages. 

 

    **Variable Attributes:** 

      - ``attributeDict`` -- dictionary with the following keywords: 

      - ``tag`` -- the html tag (a, div, span ...) 

      - ``htmlClass`` -- the html element class 

      - ``htmlId`` -- the html element id 

      - ``href`` -- linked url 

      - ``blockContent`` -- actual content to be placed in html code block 

      - ``jsEvents`` -- inline javascript event 

      - ``extraAttr`` -- extra incline css attributes and/or handles 

      - ``src`` -- source for images 

      - ``alt`` -- alternative text for images 

      - ``action`` -- action used in forms 

      - ``method`` -- method used in forms 

      - ``type`` -- type of object 

 

    **Returns:** 

      - ``block`` -- the html block 

 

    attributeDict template -- dict(tag=___, 

                                    htmlClass:divVerticalKids/divHorizontalKids, 

                                    htmlId=___, 

                                    jsEvents=___, 

                                    extraAttr=___, 

                                    blockContent=___, 

                                    href=___, 

                                    src=___, 

                                    alt=___, 

                                    action=___, 

                                    method=___, 

                                    type=___ 

                                  ) """ 

 

  # ############### > IMPORTS ################ 

  # ############### > VARIABLE SETTINGS ###### 

    d = attributeDict 

    block = '<%s ' % (d['tag'], )  # THE HTML BLOCK 

  # ############### >ACTION(S) ################ 

  # # SET THE ATTRIBUTES 

    if d.has_key('htmlClass'): 

        block += """class="%s" """ % (d['htmlClass'], ) 

    if d.has_key('htmlId'): 

        block += """id="%s" """ % (d['htmlId'], ) 

    if d.has_key('jsEvents'): 

        block += """%s """ % (d['jsEvents'], ) 

    if d.has_key('extraAttr'): 

        block += """%s """ % (d['extraAttr'], ) 

    if d.has_key('href'): 

        block += """href="%s" """ % (d['href'], ) 

        if d['href'][0] not in ['.', '/'] and 'index.py' not in d['href']: 

            block += """target="_blank" """  # OPEN EXTERNAL LINKS IN NEW TAB 

    if d.has_key('src'): 

        block += """src="%s" """ % (d['src'], ) 

    if d.has_key('alt'): 

        block += """alt="%s" """ % (d['alt'], ) 

    if d.has_key('action'): 

        block += """action="%s" """ % (d['action'], ) 

    if d.has_key('method'): 

        block += """method="%s" """ % (d['method'], ) 

    if d.has_key('type'): 

        block += """type="%s" """ % (d['type'], ) 

    block += '>' 

  # # SET THE CONTENT 

    if d.has_key('blockContent'): 

        block += str(d['blockContent']) 

  # # CLOSE THE BLOCK 

    if d.has_key('htmlId'): 

        block += '</%s><!--- /#%s --->' % (d['tag'], d['htmlId']) 

    else: 

        block += '</%s>' % (d['tag'], ) 

    return block 

 

 

 

## LAST MODIFIED : March 27, 2013 

## CREATED : March 27, 2013 

## AUTHOR : DRYX 

 

def grid_column( 

    log, 

    span=1, 

    offset=0, 

    content='', 

    htmlId=False, 

    htmlClass=False, 

    onPhone=True, 

    onTablet=True, 

    onDesktop=True, 

    ): 

    """ Get a column block for the Twiiter Bootstrap static layout grid. 

 

    **Key Arguments:** 

        - ``log`` -- logger 

        - ``span`` -- the relative width of the column 

        - ``offset`` -- increase the left margin of the column by this amount 

        - ``htmlId`` -- the id of the column 

        - ``htmlClass`` -- the class of the column 

        - ``onPhone`` -- does this column get displayed on a phone sized screen 

        - ``onTablet`` -- does this column get displayed on a tablet sized screen 

        - ``onDesktop`` -- does this column get displayed on a desktop sized screen 

 

    **Return:** 

        - ``column`` -- the column """ 

 

    if htmlId: 

        htmlId = """id="%s" """ % (htmlId, ) 

    else: 

        htmlId = '' 

    if not htmlClass: 

        htmlClass = '' 

    if onPhone: 

        onPhone = '' 

    else: 

        onPhone = 'hidden-phone' 

    if onTablet: 

        onTablet = '' 

    else: 

        onTablet = 'hidden-tablet' 

    if onDesktop: 

        onDesktop = '' 

    else: 

        onDesktop = 'hidden-desktop' 

    column = """ 

        <div class="span%s offset%s %s %s %s %s" %s> 

            %s 

        </div> 

    """ % ( 

        span, 

        offset, 

        htmlClass, 

        onPhone, 

        onTablet, 

        onDesktop, 

        htmlId, 

        content, 

        ) 

    return column 

 

 

################################################################### 

# PRIVATE (HELPER) FUNCTIONS                                      # 

################################################################### 

## SNIPPET CREATED 

## LAST MODIFIED : March 27, 2013 

## CREATED : March 27, 2013 

## AUTHOR : DRYX 

def _container( 

    responsive=True, 

    content='', 

    htmlId=False, 

    htmlClass=False, 

    onPhone=True, 

    onTablet=True, 

    onDesktop=True, 

    ): 

    """ The over-all content container for the twitter bootstrap webpage 

 

    **Key Arguments:** 

        - ``responsive`` -- fluid layout if true, fixed if false 

        - ``content`` -- html content of the container div 

        - ``htmlId`` -- the id of the container 

        - ``htmlClass`` -- the class of the container 

        - ``onPhone`` -- does this container get displayed on a phone sized screen 

        - ``onTablet`` -- does this container get displayed on a tablet sized screen 

        - ``onDesktop`` -- does this container get displayed on a desktop sized screen 

 

    **Return:** 

        - None """ 

 

    if responsive: 

        responsive = '-fluid' 

    else: 

        responsive = '' 

    if htmlId: 

        htmlId = """id="%s" """ % (htmlId, ) 

    else: 

        htmlId = '' 

    if not htmlClass: 

        htmlClass = '' 

    if onPhone: 

        onPhone = '' 

    else: 

        onPhone = 'hidden-phone' 

    if onTablet: 

        onTablet = '' 

    else: 

        onTablet = 'hidden-tablet' 

    if onDesktop: 

        onDesktop = '' 

    else: 

        onDesktop = 'hidden-desktop' 

    container = """ 

        <div class="container%s %s %s %s %s" %s> 

            %s 

        </div> 

    """ % ( 

        responsive, 

        htmlClass, 

        onPhone, 

        onTablet, 

        onDesktop, 

        htmlId, 

        content, 

        ) 

    return container 

 

################################################################### 

# TEMPLATE FUNCTIONS                                              # 

###################################################################